Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Quick Sort in C

#include <stdio.h>

void swap(int *p1, int *p2)
{
int temp = *p1;
*p1 = *p2;
*p2 = temp;
}

void show(int *arr,int n)
{
for (int i = 0; i < n;i++)
{
printf("%4d", arr[i]);
}
printf("\n");

}

void myqsort(int *arr, int iLefte, int iRight)
{
int i = iLefte;
int j = iRight;
if (i<j)
{
do {

do {
i++;
} while (arr[i]<=arr[iLefte] && i<=iRight);


do {
j--;
} while (arr[j]>=arr[iLefte] && j>iLefte);


if (i<j)
{
swap(&arr[i], &arr[j]);
}


} while (i<j);

swap(&arr[iLefte], &arr[j]);
show(arr, 10);

myqsort(arr, iLefte, j - 1);
myqsort(arr, j + 1, iRight);

}
}

void main()
{
int arr[10] = { 2, 4, 11, 333, 43, 66, 11, 32, 54, 7};

myqsort(arr, 0, 10);

show(arr, 10);
}