/* Bubble sort or Exchange sort program*/
#include
#include
#define MAX 5
void main()
{
int nos[MAX],temp,i,j,k;
int tot_pass, tot_comp, tot_exch;
char sorted = 'Y';
clrscr();
printf("Enter the numbers to be sorted - \n");
for (i=0;i
printf("Element no %d - ",i+1);
flushall();
scanf("%d",&nos[i]);
}
tot_pass = 0;
tot_comp = 0;
tot_exch = 0;
for (i=1;i
sorted = 'Y';
tot_pass = tot_pass + 1;
for (j=0;j<(MAX-i);j++)
{
tot_comp = tot_comp + 1;
if (nos[j]>nos[j+1])
{
temp = nos[j];
nos[j] = nos[j+1];
nos[j+1] = temp;
sorted = 'N';
tot_exch = tot_exch + 1;
}
}
printf("\nPass No = %d\n",i);
for (k=0;k
printf("%d ",nos[k]);
}
getch();
if (sorted == 'Y')
break;
}
printf("\n\nTotal Passes = %d",tot_pass);
printf("\n\nTotal Comparisons = %d",tot_comp);
printf("\n\nTotal Exchanges = %d",tot_exch);
printf("\n\nThe sorted numbers are :- \n");
for (i=0;i
printf("%d ",nos[i]);
}
getch();
}
Shopping In MUMBAI
Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top.
Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.
Wednesday, January 7, 2009
C Program for Bubble sort or Exchange sort
Posted by ars at 2:07 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment