Hi, im new in IT programming, our professor asks me to create or find a program that is capable of showing how a bubble sort works.. this is the program..
/*********************************************
* Demonstration program of Bubble sorting *
* (about n*n comparisons used). *
* ------------------------------------------ *
* Reference: "A book on C By Al Kelley and *
* Ira Pohl, The Benjamin/Cummings Publishing *
* Company, Inc, 1984" [BIBLI 09]. *
* *
* C++ version by J-P Moreau. *
* ------------------------------------------ *
* SAMPLE RUN: *
* *
* Initial table A: *
* 7 3 66 3 -5 22 -77 2 36 -12 *
* *
* Sorted table A: *
* -77 -12 -5 2 3 3 7 22 36 66 *
* *
*********************************************/
#include <stdio.h>
//return p,q in ascending order
void Order(int *p,int *q) {
int temp;
if(*p>*q) {
temp=*p;
*p=*q;
*q=temp;
}
}
//Buuble sorting of integer array A[]
void Bubble(int *a,int n) {
int i,j;
for (i=0; i<n; i++)
for (j=n-1; i<j; j--)
Order(&a[j-1], &a[j]);
}
void main() {
int i,n=10;
static int a[] = {7,3,66,3,-5,22,-77,2,36,-12};
printf("\n\n Initial table A:\n");
for(i=0; i<n; i++)
printf(" %d ",a[i]);
Bubble(a,n);
printf("\n\n Sorted table A:\n");
for(i=0; i<n; i++)
printf(" %d ",a[i]);
printf("\n\n");
}
//end of file bubble.cpp
there's a problem here.. when i run this program, i got this error message..
//return p,q in ascending order <- Declaration Syntax Error and the error highlighted the // stuff..
[IMG]http://i2.photobucket.com/albums/y12/smize33/Error.jpg[/IMG]
what should i do about that..