#include <stdio.h>
#include<stdlib.h>
int *intArray,n ;
void display(){
int i;
// navigate through all items
for(i = 0;i<n;i++){
printf("\n%d ",intArray[i]);
}
}
void swap(int num1, int num2){
int temp = intArray[num1];
intArray[num1] = intArray[num2];
intArray[num2] = temp;
}
int partition(int left, int right, int pivot){
int leftPointer = left -1;
int rightPointer = right;
while(1){
while(intArray[++leftPointer] < pivot){
//do nothing
}
while(rightPointer > 0 && intArray[--rightPointer] > pivot){
//do nothing
}
if(leftPointer >= rightPointer){
break;
}else{
swap(leftPointer,rightPointer);
}
}
swap(leftPointer,right);
return leftPointer;
}
void quickSort(int left, int right){
if(right-left <= 0){
return;
}else {
int pivot = intArray[right];
int partitionPoint = partition(left, right, pivot);
quickSort(left,partitionPoint-1);
quickSort(partitionPoint+1,right);
}
}
int main(){
int i;
scanf("%d",&n);
intArray=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++)
scanf("%d",intArray[i]);
quickSort(0,n-1);
display();
free(intArray);
return 0;
}
questions:–
All submissions for this problem are available.
Given the list of numbers, you are to sort them in non decreasing order.
Input
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
Output
Output given numbers in non decreasing order.
Example
Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
why i am getting fragmentation error.?