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 for strings

/* Bubble sort or exchange sort - for strings */

#include
#include
#include

#define MAX 10

void main()
{
char names[MAX][30],temp[30];
int i,j,n;
int tot_pass, tot_comp, tot_ex;
char sorted;
clrscr();
printf("Enter how many Names to be sorted [Maximum = %d] - ",MAX);
flushall();
scanf("%d",&n);
printf("\n\nEnter the array elements - ");
for (i=0;i {
printf("\nElement no %d - ",i+1);
flushall();
scanf("%s",&names[i]);
}
tot_pass = 0;
tot_comp = 0;
tot_ex = 0;
for (i=1;i {
sorted = 'Y';
tot_pass = tot_pass + 1;
for (j=0;j<(n-i);j++)
{
tot_comp = tot_comp + 1;
if ((strcmp(names[j],names[j+1]))>0)
{
strcpy(temp,names[j]);
strcpy(names[j],names[j+1]);
strcpy(names[j+1],temp);
sorted = 'N';
tot_ex = tot_ex + 1;
}
}
if (sorted == 'Y')
break;
}
printf("\nTotal passes = %d, Total comparisons = %d, Total Exchanges = %d",tot_pass, tot_comp, tot_ex);
printf("\n\nThe sorted array is :-\n");
for (i=0;i {
printf("%s ",names[i]);
}
getch();
}

C Program for Bubble sort or exchange sort for stringsSocialTwist Tell-a-Friend

0 comments:

SUPPORT THIS BLOG