1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

#include <iostream>
using namespace std;
int * myArray;
int n;
int x;
bool ascending(int left,int right){
return left<right;
}
bool descending(int left,int right){
return left>right;
}
int pivot(int myArray[],int left,int right,bool (*comparision)(int,int));
int firstSort(int myArray[],int left,int right);
void quickSort(int myArray[],int left,int right,bool (*comparision)(int,int));
void init();
int main(){
init();
x=firstSort(myArray,0,n1);
quickSort(myArray,0,x1,ascending);
quickSort(myArray,x,n1,descending);
for(int i=0;i<n;i++)
cout<<myArray[i] << " " ;
system("pause");
return 0;
}
void init(){
cout << "n=";
cin >> n;
myArray=new int[n];
for(int i=0;i<n;i++){
cout << "myArray[" << i << "]=" ;
cin >> myArray[i];
}
}
int firstSort(int myArray[],int left,int right){
while(left<right)
if(myArray[left]%2==1)
if(myArray[right]%2==0)
swap(myArray[left],myArray[right]);
else right;
else left++;
return right;
}
int pivot(int myArray[],int left,int right,bool (*comparision)(int,int)){
int nrOfSwaps=0;
while(left<right){
if(!comparision(myArray[left],myArray[right])){
swap(myArray[left],myArray[right]);
nrOfSwaps++;
}
if(nrOfSwaps%2==0)right;
else left++;
}
return right;
}
void quickSort(int myArray[],int left,int right,bool (*comparision)(int,int)){
if(left<right){
quickSort(myArray,left,pivot(myArray,left,right,comparision)1,comparision);
quickSort(myArray,pivot(myArray,left,right,comparision)+1,right,comparision);
}
}
 