Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void quicksort(int num[50],int left,int right){
- int i, j, pivot, temp;
- if(left<right){
- pivot=left;
- i=left;
- j=right;
- while(i<j){
- while(num[i]<=num[pivot]&&i<right)
- i++;
- while(num[j]>num[pivot])
- j--;
- if(i<j){
- temp=num[i];
- num[i]=num[j];
- num[j]=temp;
- }
- }
- temp=num[pivot];
- num[pivot]=num[j];
- num[j]=temp;
- quicksort(num,left,j-1);
- quicksort(num,j+1,right);
- }
- }
- int main(){
- int i, count, num[50];
- printf("The number of elements we are going to enter: ");
- scanf("%d",&count);
- printf("Enter %d elements: ", count);
- for(i=0;i<count;i++)
- scanf("%d",&num[i]);
- quicksort(num,0,count-1);
- printf("Sorted in Ascending order: ");
- for(i=0;i<count;i++)
- printf(" %d",num[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement