/* Bubble Sort, Exchange Sort */
#include
#include
#define MAXNOS 100 /* Macro definition for maximum numbers to be input */
#define TRUE 1 /* Macro definition for TRUE */
#define FALSE 0 /* Macro defintion for FALSE */
void bubble(int [], int); /* sorting function prototype declaration */
void main(void)
{
int a[MAXNOS]; /* array to hold the input numbers */
int m; /* stores the total count of input numbers */
int i; /* for loop variable */
input : /* label name for transfer of control through goto */
clrscr();
printf("Bubble Sort\n");
printf("------ ----\n\n");
printf("Enter how many numbers will be input for sorting - ");
flushall();
scanf("%d", &m);
if (m < 1 || m > MAXNOS) /* check for valid input */
{
printf("Error - input value is out of range...");
getch();
goto input;
}
printf("Enter the numbers one by one -\n");
for (i=0; i
printf("%2d - ", (i+1));
flushall();
scanf("%d", &a[i]);
}
bubble(a, m); /* function is invoked for sorting the numbers */
printf("\n\nSorted numbers are - \n");
for (i=0; i
getch();
}
void bubble(int x[], int n) /* function definition begins here */
{
int i, j, hold, switched;
switched = TRUE;
for (i=1; i
switched = FALSE; /* set the switched status to false for a new pass */
for (j=0; j<(n-i); j++) /* start comparing loop */
{
if (x[j] > x[j+1] ) /* compare and exchange, if required */
{
hold = x[j];
x[j] = x[j+1];
x[j+1] = hold;
switched = TRUE; /* set the switched status to true */
} /* end of if statement */
} /* end of comparisons loop */
} /* end of pass loop */
} /* end of bubble function */
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.
Sunday, May 31, 2009
Data Structure Program -Bubble Sort, Exchange Sort
Posted by ars at 9:06 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment