9.selsort and 10.quicksort Programs
9.selsort and 10.quicksort Programs
Design and implement C/C++ Program to sort a given set of n integer elements using Selection Sort
method and compute its time complexity. Run the program for varied values of n> 5000 and record the
time taken to sort. Plot a graph of the time taken versus n. The elements can be read from a file or can
be generated using the random number generator. analysis: worst case, average case and best case.
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main()
{
int a[10000],n, i;
struct timeval t;
double s, e;
temp=a[low];
a[low]=a[j];
a[j]=temp;
return j;
}
void qsort(int a[], int low, int high)
{
if(low<high)
{
int s=partition(a, low, high);
qsort(a,low,s-1);
qsort(a,s+1,high);
}
}
int main()
{
int a[10000],n, i;
struct timeval t;
double s, e;
gettimeofday(&t,NULL);
s=t.tv_sec+(t.tv_usec/1000000.0);
qsort(a, 0, n-1);
gettimeofday(&t,NULL);
e=t.tv_sec+(t.tv_usec/1000000.0);