Professional Documents
Culture Documents
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int *a,n,i,j;
void quicksort();
int partition();
void main(){
clrscr();
scanf("%d",&n);
a = (int*)calloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("%d ",a[i]);
quicksort(0,n-1);
printf("%d ",a[i]);
getch();
}
C program for Quick Sort
if(low<high){
j=partition(low,high);
quicksort(low,j-1);
quicksort(j+1,high);
} }
int temp,pivot;
pivot=low;
i=low;
j=high;
while(i<j){
while((i<high)&&(a[i]<=a[pivot])){
i=i+1;
while(a[j]>a[pivot]){
j=j-1;
if(i<j){
temp=a[i];
a[i]=a[j];
a[j]=temp;
temp=a[pivot];
a[pivot]=a[j];
a[j]=temp;
return j;