0% found this document useful (0 votes)
2 views2 pages

Quick Sort

The document contains a C++ program that implements the Quick Sort algorithm. It prompts the user to enter the number of elements and the elements themselves, then sorts the array using the Quick Sort method while displaying the sorting process. Finally, it outputs the sorted array.

Uploaded by

rathimala2007com
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Quick Sort

The document contains a C++ program that implements the Quick Sort algorithm. It prompts the user to enter the number of elements and the elements themselves, then sorts the array using the Quick Sort method while displaying the sorting process. Finally, it outputs the sorted array.

Uploaded by

rathimala2007com
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<iostream>

#include<conio.h>
#include<string.h>
using namespace std;
int n1;
class quick
{
public:
int pass=0;
void quicksort(int a[],int left,int right)
{
int pivot,i,j,temp;
if(left<right)
{
pass++;
i=left;
j=right+1;
pivot = a[left];
cout<<"\n\t "<<pass<<" \t "<<pivot<<" \t
"<<left<<" \t "<<right<<" \t ";
while(i<j)
{

do i++; while(a[i]<pivot);
do j--; while(a[j]>pivot);

if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[left];
a[left]=a[j];
a[j]=temp;
for(i=1;i<=n1;i++)
cout<<" "<<a[i];
quicksort(a,left,j-1);
quicksort(a,j+1,right);
}
}
};
int main()
{
quick obj;
int n,i,a[20];
cout<<"\n\t Quick Sort";
cout<<"\n\t __________";
cout<<"\n\t Enter the no. of elements: ";
cin>>n;
n1=n;
cout<<"\n\t Enter the Array Elements: ";
for(i=1;i<=n;i++)
{
cout<<"\n\t";
cin>>a[i];
}
cout<<"\n\t Number of Elements : "<<n;
cout<<"\n\n\t Unsorted Data : ";
for(i=1;i<=n;i++)
cout<<a[i]<<"\t";
cout<<"\n";
cout<<"\n\t
_________________________________________________________________";
cout<<"\n\t Pass \t Pivot \t Left \t Right \t\t Elements ";
cout<<"\n\t
_________________________________________________________________";
[Link](a,1,n);
cout<<"\n\n\t Sorted Data : ";
for(i=1;i<=n;i++)
{
cout<<a[i]<<"\t";
}
return 0;
}

You might also like