WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
 
Forum
Pages (2) [1] 2   ( Go to first unread post )

Bubble Sort, Code snippet for a bubble sorting technique

vulPeCula
Quote Post


Extremely Active Member
******

Group: Members
Posts: 190
Member No.: 16362
Joined: 16-December 08


Sponsored Links
Hello guys this is a code for bubble sort as sorting techniques are used at some places so here's a code and exe file.
[Code is written in C and compiled in Borland C IDE].

I hope its useful.

Regards,
vulPeCula. cheers.gif

Attached File ( Number of downloads: 30 )
 Login or Register to download
PMEmail PosterMSN
Top
Jupiter
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 738
Member No.: 773
Joined: 10-November 04


Thank you for sharing.

Fix typos in source:

teh -> the
Temprary -> Temporary
PMEmail Poster
Top
vulPeCula
Quote Post


Extremely Active Member
******

Group: Members
Posts: 190
Member No.: 16362
Joined: 16-December 08


tongue.gif smile.gif
PMEmail PosterMSN
Top
Elena
Quote Post


New Member
*

Group: Members
Posts: 3
Member No.: 47659
Joined: 14-November 11


Implementing Bubble Sort in C#
using System;

class AscendingBubbleSort
{
public static void Main()
{
int i,j,t;
int []p=new int[10];
int []q=new int[10];
int []c=new int[20];
for(i=0;i<10;i++)
{
Console.WriteLine("Enter Value");
p[i]=int.Parse(Console.ReadLine());
}
for(i=0;i<10;i++)
{
Console.WriteLine("Enter Value");
q[i]=int.Parse(Console.ReadLine());
}

if(j<10)
c[j]=p[j];
else
c[j]=q[j-10];

// Sorting: Bubble Sort
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
if(c[i]>c[j])
{
t=c[i];
c[i]=c[j];
c[j]=t;
}
}
}

// Print the contents of the sorted array
for(i=0;i<20;i++)
{
Console.WriteLine (c[i]);
}
}

}
PMEmail Poster
Top
Cosmin_NTG
Quote Post


New Member
*

Group: Members
Posts: 1
Member No.: 49432
Joined: 7-February 12


That's not the most optimized implementation of Bubble sort because the program performs n^2 steps for sorting that array (those steps are performed even the array is already sorted). An optimized implementation is this:
CODE
#include<iostream>
using namespace std;
int main()
{  int n, v[100], i, aux, x;
   cout<<"n="; cin>>n;
   for(i=1; i<=n; i++) {cout<<"v["<<i<<"]="; cin>>v[i];}
   do{
   x=0;
  for(i=1; i<=n-1; i++)
     if(v[i]>v[i+1]
       {   aux=v[i]; v[i]=v[i+1]; v[i+1]=aux; x=1; }
  while(x);
 for(i=1; i<=n; i++) cout<<v[i]<<" ";
 return 0;
}

The program should compile ok (I didn't compile it) on any GNU GCC compiler. It's written in C++.
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (2) [1] 2  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian