View Single Post
Light Poster
14Dec2011,01:31  
chetan3191's Avatar
Code:
#include<stdio.h>
void quick(int[],int);

main(){
int a[]={11,2,5,4,7,3};
int len=sizeof(a)/sizeof(a[0]);
quick(a,len);

int i=0;
while(i<len){
printf("%d,",a[i]);
i++;
}
}





void quick(int a[],int len){

int pivot=a[0];
int loc=0;
int i=0,j=len-1;

while(i!=j){

while(j>=0 && i!=j ){
if(a[j]<pivot){
    printf("asdasdad");
a[loc]=a[j];
loc=j;
break;
}
j--;
}

while(a[i]<len && i!=j){
if(a[i]>pivot){    
a[loc]=a[i];
loc=i;
break;
}
i++;
}

}

a[i]=pivot;
}

copy this code and paste it in ur compiler...this is the first basic quick sort step...for the above given array elements this code goes into infinite loop and i am too stupid to understand the reason behind it.....kindly help me out guyzzz!!

Last edited by shabbir; 14Dec2011 at 09:04.. Reason: Code blocks