61. QUICK SORT
void main()
{
  int x[20],size,i;
  clrscr();
  printf("\nEnter size of the array :");
  scanf("%d",&size);
  printf("\nEnter %d elements :",size);
  for(i=0;i
            scanf("%d",&x[i]);
  quicksort(x,0,size-1);
  printf("\nSorted elements :");
  for(i=0;i
            printf(" %d",x[i]);
  getch();
}
quicksort(int x[10],int first,int last)
{
  int pivot,j,temp,i;
  if(first
  {
            pivot=first;
            i=first;
            j=last;
            while(i
            {
                        while(x[i]<=x[pivot]&&i
                                    i++;
                        while(x[j]>x[pivot])
                                    j--;
                        if(i
                        {
                                    temp=x[i];
                                    x[i]=x[j];
                                    x[j]=temp;
                        }
            }
            temp=x[pivot];
            x[pivot]=x[j];
            x[j]=temp;
            quicksort(x,first,j-1);
            quicksort(x,j+1,last);
  }
}

 
 
 
 
No comments:
Post a Comment
Thanks to given comments.......