Quick Sort Algorithm Geeksforgeeks Code Example


Example: quick sort program in c

#include<stdio.h> void quicksort(int number[25],int first,int last){    int i, j, pivot, temp;     if(first<last){       pivot=first;       i=first;       j=last;        while(i<j){          while(number[i]<=number[pivot]&&i<last)             i++;          while(number[j]>number[pivot])             j--;          if(i<j){             temp=number[i];             number[i]=number[j];             number[j]=temp;          }       }        temp=number[pivot];       number[pivot]=number[j];       number[j]=temp;       quicksort(number,first,j-1);       quicksort(number,j+1,last);     } }  int main(){    int i, count, number[25];     printf("How many elements are u going to enter?: ");    scanf("%d",&count);     printf("Enter %d elements: ", count);    for(i=0;i<count;i++)       scanf("%d",&number[i]);     quicksort(number,0,count-1);     printf("Order of Sorted elements: ");    for(i=0;i<count;i++)       printf(" %d",number[i]);     return 0; }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable