Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Wednesday, April 21, 2010

This program is used for Quick sort. (C++)


This program is used for Quick sort
 
#include< iostream.h>
#include< conio.h>
#include< stdlib.h>
void quick_sort(int array[],int first, int last)
{
int temp,low, high, pivot;
low=first;
high=last;
pivot=array[(first+last)/2];
do{
while(array[low]< pivot)
low++;
while(array[high]>pivot)
high--;
if(low< =high)
{
temp=array[low];
array[low++]=array[high];
array[high--]=temp;
}
} while(low< =high);
if(first< high)
quick_sort(array,first,high);
if(low< last)
quick_sort(array,low,last);
}
void main(void)
{
clrscr();
int values[100],i;
cout< < "\n Unsorted list is as follows \n";
for(i=0;i< 20;i++)
{
values[i]=rand() %100;
cout< < " "< < values[i];
}
quick_sort(values,0,19);
cout< < "\nSorted list as follows \n";
for(i=0;i< 20;i++)
cout< < " "< < values[i];
} 

Related Posts by Categories



0 comments:

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP