QUICK SORT
AIM:
To Write a program to sort the elements in ascending order using Quick Sort.

ALGORITHM:
STEP 1: Start the program
STEP 2: Create a template variable W
           STEP 3: Create and define a class quick
           STEP 4:In private create a template type array variable
STEP 5:In public declare get, sort, and partition and put functions
STEP 6:        Define the get function out side the class using   operator and get                           
the values
STEP 7:        Define the sort function outside the class using   operator 
STEP 8: Check the condition if (p<q) if the condition is true sort the values
STEP 9: Define the function partition outside the class using operator
STEP 10:Create a generic variable V
STEP 11:Check do while condition 
While (a[i]<v) if condition true then swap the values
STEP 12:Check another condition whether i<j, if true then swap the values
STEP 13:Define the function put outside the class using          operator and 
display the sorted values
STEP 14:Create an object q1 and q2 for the class quick 
STEP 15:Invoke the function put and get using object q1 and q2
STEP 16:Stop the program execution.



PROGRAM:
#include<iostream.h>
#include<conio.h> #include<stdlib.h>
#define SIZE 10
class Quick{
private:
int arr[SIZE];
public:
int get_data(int);
void quicksort(int,int); int partition(int,int);
void swap(int,int);
void display(int);
};
int Quick::get_data(int n)
{
int i;
cout<<"\n enter total numbers to sort:";
cin>>n;
for(i=0;i<n;i++){
cout<<"\n enter elements";
cin>>arr[i];
}
return n;
}
void Quick::quicksort(int p,int q)
{
int j;
if(p<q)
{
j=partition(p,q+1);
quicksort(p,j-1); quicksort(j+1,q);
}
}
int Quick::partition(int m,int p)
{
int pivot=arr[m];
int i=m,j=p;
 do
{
i++;
}while(arr[i]<pivot);
do
{
j--;
}while(arr[j]>pivot);
if(i<j)
swap(i,j);
}while(i<j);
arr[m]=arr[j];
arr[j]=pivot;
return j;
}
void Quick::swap(int i,int j)
{
int p;
p=arr[j];
arr[i]=arr[j];
arr[j]=p;
}
void Quick::display(int n)
{
for(int i=0;i<n;i++) cout<<"  "<<arr[i];
}
void main()
{
Quick obj;
int n,i;
clrscr();
cout<<"\n\t\t Quick sort method \n";
n=obj.get_data(n);
obj.quicksort(0,n-1);
cout<<"\n\n\t sorted array is:\n";
obj.display(n);
getch();
}
OUTPUT:
Quick Sort Method
Enter Total numbers to sort : 5
Enter Element 30
Enter Element 50 Enter Element 10 Enter Element 20 Enter Element 40
  Sorted Array Is:
10 20 30 40 50