Professional Documents
Culture Documents
h"
#include "stdlib.h"
#include "math.h"
int b[high-low+1];
flag = 0;
low = 0;
high = n-1;
int main()
{
int *a = NULL;
int n,key,i,choice;
while(1) {
printf("EXIT : 0\n");
printf("BUBBLE SORT : 1\n");
printf("SELECTION SORT : 2\n");
printf("INSERTION SORT : 3\n");
printf("MERGE SORT : 4\n");
printf("QUICK SORT : 5\n");
printf("LINEAR SEARCH : 6\n");
printf("BINARY SEARCH : 7\n");
scanf("%d", &choice);
if(choice == 0)
exit(0);
a = (int *)calloc(n,sizeof(int));
for(i = 0; i < n; i++) {
printf("a[%d] = ", i);
scanf("%d",&a[i]);
}
if(choice >= 1 && choice <= 5) {
printf("The array before sorting:\n");
print(a, n);
}
if(choice >= 6 && choice <= 7) {
printf("Enter the key to be searched:\n");
scanf("%d", &key);
printf("The array before searching:\n");
print(a, n);
}
switch(choice) {
case 1:
bubblesort(a,n);
break;
case 2:
selectionsort(a,n);
break;
case 3:
insertionsort(a,n);
break;
case 4:
mergesort(a,0,n-1);
break;
case 5:
quicksort(a,0,n-1);
break;
case 6:
linearsearch(a,n,key);
break;
case 7:
binarysearch(a,n,key);
break;
default:
printf("You have made a wrong choice\n.");
}
if(choice >= 1 && choice <= 5) {
printf("The array after sorting:\n");
print(a, n);
}
if(a != NULL) {
free(a);
a = NULL;
}
}
return 0;
}