Skip to main content

Posts

Showing posts from August 7, 2017

QUICK SORT

CODING: #include<stdio.h> #include<conio.h> int partition(int list[],int beg,int end); void quick_sort(int list[],int beg,int end); void main() { int arry[50],i,n; clrscr(); printf("How many enter the element:"); scanf("%d",&n); for(i=0;i<n;i++)  {   printf("Enter the number:");   scanf("%d",&arry[i]);  } quick_sort(arry,0,n-1); printf("YOUR SORTED LIST:\n");  for(i=0;i<n;i++) printf("%d\n",arry[i]); getch(); } void quick_sort(int list[],int beg,int end) { int loc; if(beg<end)  {  loc=partition(list,beg,end);  quick_sort(list,beg,loc-1);  quick_sort(list,loc+1,end);  } } int partition(int list[],int beg,int end) { int left,right,temp,loc,flag; loc=left=beg; right=end; flag=0; while(flag!=1) {  while((list[loc]<=list[right]) && (loc!=right))     right--;   if(loc==right)     flag=1;   else if(list[loc]>list[right])    {     temp=list[loc];