You are viewing a single comment's thread. Return to all comments →
//heqder flies
//quicksort function
void quickSort(int *a, int s) //s = size //p = pivot //temp is the temaprary variable { //conditional statement if(s > 1){
int temp, p = a[0], up = (s-1);
//loop condition for(int l = s-1; l >= 0; --l){
if(a[l] >= p){
temp = a[l];
int m = l;
while(m < up){
a[m] = a[m+1];
++m;
}
a[up--] = temp;
} }
++up;
quickSort(a, up);
quickSort(a+up+1, s-up-1);
//statement for printing output
for(int l = 0; l < s; ++l){
printf("%d ", a[l]);
printf("\n"); }
} //main block int main(void){ //n=no.of.elements
int n;
scanf("%d", &n);
int a[n]; //scanning array
for(int l = 0; l < n; l++) {
scanf("%d", &a[l]);
//function call quickSort(a, n);
//it reprasents '0' error return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →
//heqder flies
include
include
include
include
include
//quicksort function
void quickSort(int *a, int s) //s = size //p = pivot //temp is the temaprary variable { //conditional statement if(s > 1){
int temp, p = a[0], up = (s-1);
//loop condition for(int l = s-1; l >= 0; --l){
if(a[l] >= p){
temp = a[l];
int m = l;
while(m < up){
a[m] = a[m+1];
++m;
}
a[up--] = temp;
} }
++up;
quickSort(a, up);
quickSort(a+up+1, s-up-1);
//statement for printing output
for(int l = 0; l < s; ++l){
printf("%d ", a[l]);
}
printf("\n"); }
} //main block int main(void){ //n=no.of.elements
int n;
scanf("%d", &n);
int a[n]; //scanning array
for(int l = 0; l < n; l++) {
scanf("%d", &a[l]);
}
//function call quickSort(a, n);
//it reprasents '0' error return 0;
}