Sun Sep 07, 2008 6:11 pm
#include<iostream>
int* BubbleSort(int* a);
using namespace std;
void main()
{
int sort[10], i;
int* psort = 0;
psort = sort;
printf("Enter 10 numbers: \n");
for(i=0; i<10; i++) {
printf("%d: ", (i+1));
cin >> sort[i];
}
printf("\nBefore sorted: ");
for(i=0; i < 10; i++) {
printf("%d ", sort[i]);
}
printf("\n\n After Sorted: ");
psort = BubbleSort(psort);
for(i=0; i < 10; i++) {
printf("%d ", sort[i]);
}
printf("\n");
}
int* BubbleSort(int* a) {
int c = 0;
int d = 0;
do {
d = 0;
for(int b = 0; b < 9; b++) {
if(a[b] > a[b+1]) {
c = a[b];
a[b] = a[b+1];
a[b+1] = c;
d++;
}
}
}while(d);
return a;
}
Sun Sep 07, 2008 7:57 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.