Created
July 10, 2016 14:18
-
-
Save talwinder777/b2cd00a71a7d5908b9b660545977ffb4 to your computer and use it in GitHub Desktop.
my quick sort is not running............plz see for the problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int n; | |
main() | |
{ | |
int data[20],i; | |
scanf("%d",&n); | |
fflush(stdin); | |
for(i=0;i<n;i++) | |
{ | |
scanf("%d",&data[i]); | |
} | |
fflush(stdin); | |
qsort(data,0,n-1); | |
for(i=0;i<n;i++) | |
{ | |
printf("%d ",data[i]); | |
} | |
} | |
qsort(data,start,end) | |
int data[],start,end; | |
{ | |
int p; | |
if(start>=end)return; | |
else { | |
p=partition(data,start,end); | |
qsort(data,start,p); | |
qsort(start,p+1,end);} | |
} | |
int partition(data,left,right) | |
int data[],left,right; | |
{ | |
int i=left,j=right,pivot=data[left]; | |
int temp; | |
while(i<j){ | |
while((i<j)&&(data[i]<pivot))i++; | |
while((i<j)&&(data[j]>=pivot))j--; | |
if(i<j){ | |
temp=data[i]; | |
data[i]=data[j]; | |
data[j]=temp;} | |
} | |
if(data[j]<=pivot) | |
return(j); | |
else | |
return(j-1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment