Program for Quick Sort


#include<iostream>
#include<iomanip>
using namespace std;
int split(double a[],int low,int high);
void quick(double a[],int low,int high);
int main()
{
 int i,j,n;
 cout<<"\nenter the no of integers : ";

 cin>>n;
 double a[n];

 int k=n;
 cout<<"\nenter the integers : ";

 for(i=0;i<n;i++)
 {
  cin>>a[i];
 }
 cout<<"\narray before sorting : ";

 for(i=0;i<n;i++)
 {
  cout<<a[i]<<" ";
 }

 cout<<"\n";

 quick(a,0,n-1);

 cout<<"\nafter sorting : ";

 for(i=0;i<n;i++)
 {
  cout<<a[i]<<" ";
 }
 cout<<"\n";
return 0;
}

void quick(double a[],int low,int high)
{
 int i;
 if(high>low)
 {
  i=split(a,low,high);
  quick(a,low,i-1);
  quick(a,i+1,high);
 }
}
int split(double a[],int low,int high)
{
 int p,q;
 double i,t;
 p=low+1;
 q=high;
 i=a[low];
 
 while(q>p)
 {
  while(i>a[p])
  p++;
  
  while(i<a[q])
  q--;
  
  if(q>p)
  {
   t=a[p];
   a[p]=a[q];
   a[q]=t;
  }
 }
 t=a[low];
 a[low]=a[q];
 a[q]=t;
 
 return q;
}