Code:
#include <iostream>
#include <cstdlib>
#define SWAP(a,b,c) { a=c; c=b; }
#define INDEX 8
using namespace std;
void bubble_srt(int a[], int n);
int main(void)
{
int array[INDEX] = {12, 8, 35, 92, 19}; //Altered the numbers...
cout<<"Before sorting:"<< endl;
for(int i=0; i<INDEX; i++)
cout<< array[i]<< endl;
bubble_srt(array, INDEX);
cout<<"After the sort:"<< endl;
for(int i=0; i<INDEX; i++)
cout<< array[i]<< endl;
system("pause");
return 0;
}
void bubble_srt(int a[], int n)
{
int i, j;
for(i=0; i<n; i++)
{
for(j=1; j<(n-1); j++)
{
if(a[j-1]<a[j]);
SWAP(a[j-1],a[j-1], a[j]);
}
}
}
You forgot a semicolon in your function and a comma in your array..also I don't really know the rules about macros since I haven't really used them, but adding another argument to use as a tmp worked...just pass the first value twice
Code:
SWAP(val1,val1,val2);