#include <stdio.h>
int quickSort(int argv[],int low,int high);
int selectionSort(int argv[],int);
int main(void)
{
int temp[10] = {45,64,234,56,34,345,346,765,224,645};
int temp1[10] = {45,64,234,56,34,345,346,765,224,645};
int sum = selectionSort(temp,10);
for(int i=0;i<10;i++)
{
printf("%d\n",temp[i]);
}
sum = quickSort(temp1,0,9);
for(int i=0;i<10;i++)
{
printf("%d\n",temp1[i]);
}
return 0;
}
int selectionSort(int argv[],int size)
{
int time =0;
for(int i=0;i<size;i++)
{
int minIndex = i;
for(int j=i+1;j<size;j++)
{
++time;
if(argv[j] < argv[minIndex])
{
minIndex = j;
}
}
if(minIndex !=i)
{
int temp = argv[i];
argv[i] = argv[minIndex];
argv[minIndex] = temp;
}
}
return time;
}
int quickSort(int argv[],int low,int high)
{
int key,L,H,time=0;
time++;
if(low>=high)
return time;
H=high;
L=low;
key=argv[low];
while(H != L)
{
if(L<H && argv[H] >= key)
H--;
argv[L]=argv[H];
if(L<H && argv[L] <= key)
L++;
argv[H]=argv[L];
}
argv[L] = key;
quickSort(argv,low,L-1);
quickSort(argv,L+1,high);
return time;
}
int quickSort(int argv[],int low,int high);
int selectionSort(int argv[],int);
int main(void)
{
int temp[10] = {45,64,234,56,34,345,346,765,224,645};
int temp1[10] = {45,64,234,56,34,345,346,765,224,645};
int sum = selectionSort(temp,10);
for(int i=0;i<10;i++)
{
printf("%d\n",temp[i]);
}
sum = quickSort(temp1,0,9);
for(int i=0;i<10;i++)
{
printf("%d\n",temp1[i]);
}
return 0;
}
int selectionSort(int argv[],int size)
{
int time =0;
for(int i=0;i<size;i++)
{
int minIndex = i;
for(int j=i+1;j<size;j++)
{
++time;
if(argv[j] < argv[minIndex])
{
minIndex = j;
}
}
if(minIndex !=i)
{
int temp = argv[i];
argv[i] = argv[minIndex];
argv[minIndex] = temp;
}
}
return time;
}
int quickSort(int argv[],int low,int high)
{
int key,L,H,time=0;
time++;
if(low>=high)
return time;
H=high;
L=low;
key=argv[low];
while(H != L)
{
if(L<H && argv[H] >= key)
H--;
argv[L]=argv[H];
if(L<H && argv[L] <= key)
L++;
argv[H]=argv[L];
}
argv[L] = key;
quickSort(argv,low,L-1);
quickSort(argv,L+1,high);
return time;
}