here are the errors and the code
C:\matty\Microsoft Visual Studio\sorts.c(145) : error C2143: syntax error : missing ')' before ';'
C:\matty\Microsoft Visual Studio\sorts.c(145) : error C2059: syntax error : ')'
C:\matty\Microsoft Visual Studio\sorts.c(146) : error C2143: syntax error : missing ';' before 'if'
------------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define num 5
int array[num];
int sarray[num];
int swap;
int compare;
int iswap=0;
int icompare=0;
int shswap;
int shcompare;
int bswap;
int bcompare;
int current;
void exch(int sarray[]);
void ins_sort(int sarray[]);
void shell_sort(int sarray[]);
main()
{
int ctr=0,ctr1=0,ctr3=0;
for(ctr1=0;ctr1<num;ctr1++)
{
array[ctr1]=(rand()%100);
}
for(ctr1=0;ctr1<num;ctr1++)
{
sarray[ctr3]=array[ctr1];
ctr3++;
}
//print sorted array
for(ctr3=0;ctr3<num;ctr3++)
{
printf("%d\t",sarray[ctr3]);
}
printf("Stats for Exchange sort");
printf("%d\nNumber of swaps",swap);
printf("%d\nNumber of comparisons",compare);
printf("Stats for Insertion sort");
printf("%d\nNumber of swaps",iswap);
printf("%d\nNumber of comparisons",icompare);
printf("Stats for Shell sort");
printf("%d\nNumber of swaps",shswap);
printf("%d\nNumber of comparisons",shcompare);
printf("Stats for Bubble sort");
printf("%d\nNumber of swaps",bswap);
printf("%d\nNumber of comparisons",bcompare);
return 0;
}
/******************************************/
void exch(int sarray[])
/******************************************/
{
int temp, //buffer var, same type as array elements
other, current; // loop counters
compare=0;
swap=0;
for (current = 0; current < num-1; current ++)
{
for (other = current+1; other < num; other ++)
if (sarray[current] > sarray[other],compare++)
//the current element is greater than the other element
{
//swap the 2 elements
temp = sarray[current];
sarray[current] = sarray[other];
sarray[other] = temp;
swap++;
}
}
}
/******************************************/
void ins_sort(int sarray[])
/*
nb: number of elements in the array to be sorted
ar[]: name of array to be sorted
*/
/******************************************/
{
int temp, //buffer var of same type as array elements
sub,next; //loop counters
for (sub = 0; sub < num; sub++)
{
temp = sarray[sub];
for (next = sub-1; temp < sarray[next] && next >= 0; next--)
//search for insertion position
{
sarray[next+1] = sarray[next];
}
sarray[next+1] = temp;
}
}
/******************************************/
void shell_sort(int sarray[])
/*
nb: number of elements in the array to be sorted
ar[]: name of array to be sorted
*/
/******************************************/
{
int temp, //buffer var same type as elements of array
ind, //loop counter
other, // subscript of corresponding element in other partition
interval, //size of interval
finish; //boolean flag to indicate the sort is finished
for (interval = num/2; interval >= 1; interval /= 2)
{
do
{
finish = 1; //sort is finished while there is no further swap
for (ind = 0; ind < num-interval; ind++)
{
other = ind + interval;
if (sarray[ind] > sarray[other],shcompare++)
{
temp = sarray[ind];
sarray[ind] = sarray [other];
sarray [other] = temp;
shswap++;
finish = 0;
}
}
} while (!finish);
}
}
/************************************************** ***/
void bubbles(int sarray[])
/************************************************** ***/
{
int temp, //buffer var, same type as array elements
sub, current, // loop counters
finish; // flag to signal the sort is finished
// (to avoid unnecessary comparisons)
for (sub = num, finish = 0; sub > 0 && !finish; sub--)
{
finish = 1; // sort is finished if we don't swap 2 elements
for (current = 0; current < sub-1; current++;bcompare++)
if (sarray[current] > sarray[current+1])
//the current element is greater than the next element
{
//swap the 2 elements
temp = sarray[current+1];
sarray[current+1] = sarray[current];
sarray[current] = temp;
bswap++;
finish = 0; //sort is not finished (2 elements have been swapped)
}
}
}