Pages

E-mail us at prgms4starters@gmail.com for any queries or to share your programs. Please mention the program definition in the subject line.

In case you need help in finishing a program, do mention "incomplete pgm" in the subject line. Our team of experts will do their best to help you.

Click the link to follow this page for updates and reminders: FOLLOW THIS SITE

You can also visit our Facebook page by clicking HERE

**don't forget to participate in the polls at the bottom of the page

Friday, November 5, 2010

Quick Sort Using Recursion in C++

#include<iostream>
#include<conio.h>
#include<stdio.h>

using namespace std;

void qsort(int data[],int low,int high);

void main()
{
system("cls");
int data[50],n,c=1;
while(c==1)
{
cout<<"\nEnter the size of the array: "; cin>>n;
cout<<"\n\nEnter the elements of the array"; for(int i=0;i<n;i++)
{
cin>>data[i];
cout<<"\n"; } getch(); qsort(data,0,n-1); cout<<"\nThe sorted array is: \n"; for(i=0;i<n;i++)
{
cout<<" "<<data[i];
}
cout<<"\n\nPress 1 to continue: "; cin>>c;
}
}
void qsort(int data[],int low,int high)
{
int pivot,temp,i,j;
i=low;
j=high;
pivot=data[(low+high)/2];
while(i<=j) { while(data[i]<pivot)
i++;
while(pivot<data[j])
j--;
if(i<=j) { temp=data[i]; data[i]=data[j]; data[j]=temp; i++; j--; } } if(low<j)
(data,low,j);
if(i<high)
qsort(data,i,high);
}





- Benil Babu Mathew
 

No comments:

Post a Comment

We have noticed that 20% of our visitors are still using internet explorer. For a better and faster surfing experience we recommend that you switch to either Google Chrome or Mozilla Firefox. We cannot provide you the downloads but here are the links to sites where you can download them from

Google Chrome - click here to go to site

Mozilla Firefox - click here to go to site

Where are you from

Do you think this site was helpful

Should we put up more C or C++ programs