Raw 7
Raw 7
Raw 7
h>
void swap (int a[], int left, int right)
{
int temp;
temp=a[left];
a[left]=a[right];
a[right]=temp;
}
a[low] = a[right];
a[right] = pivot_item;
return right;
}
int main()
{
int a[50], i, n;
printf("\nEnter no. of elements: ");
scanf("%d", &n);
printf("\nEnter the elements: \n");
for (i=0; i<n; i++)
scanf ("%d", &a[i]);
printf("\nUnsorted elements: \n");
printarr(a,n);
quicksort(a,0,n-1,n);
printf("\nSorted elements: \n");
printarr(a,n);
}
//////////////////////////////////////////////////////////////////////
OUTPUT:
Enter no. of elements: 6
Unsorted elements:
10 21 32 45 66 78
10 is pivot element
10 21 32 45 66 78
21 is pivot element
10 21 32 45 66 78
32 is pivot element
10 21 32 45 66 78
45 is pivot element
10 21 32 45 66 78
66 is pivot element
10 21 32 45 66 78
Sorted elements:
10 21 32 45 66 78
Process returned 0 (0x0) execution time : 16.524 s
Press any key to continue.