algorithm the user choose the pivot

in this program i want from the user choose if he want the pivot in the first or last !


//
// main.cpp
// pivot
//
// Created on 12/18/13.
// Copyright (c) 2013. All rights reserved.
//

#include <iostream>

using namespace std;
int pivot(int *S[],int first,int last);
void Qiucksort(int *S,int first,int last);

int main()
{
int size,first=0,last;
cout<<"Enter the size: ";
cin>>size;
last=size-1;
int *S=new int [size];
cout<<"Enter the Array : "<<endl;
for(int i=0;i<size;i++)
cin>>S[i];

Qiucksort(S ,first , last);

cout<<endl<<endl;
for(int i=0;i<=last;i++)
cout<<S[i]<<" ";
cout<<endl;
}
int pivot(int *S,int first,int last)
{
int pio=S[first];
for(int i=first+1;i<=last;i++)
{
if(pio>S[i])
{
S[first]=S[i];
S[i]=S[first+1];
S[first+1]=pio;

first=first+1;
}
}
return first;
}
void Qiucksort (int *S ,int first , int last)
{
int m;
if(first<last)
{
m=pivot(S,first,last);
Qiucksort (S , first ,m-1);
Qiucksort ( S ,m+1,last);

}
}
Last edited on
Topic archived. No new replies allowed.