#include <bits/stdc++.h>
using namespace std;
int myArray[1000]={0};
void arrayPrint(int arr[],int s,int e){
for(int i=s;i<e;i++)printf("%d ",arr[i]);
printf("\n\n");
}
void MaxHeapAdject(int arr[],int root,int length){
for(int i=length/2;i>=root;i--)
for(int j=i*2;j<=length;j*=2){
if(j+1<=length&& arr[j+1]>arr[j])j++;
if(arr[j]>arr[i])swap(arr[j/2], arr[j]);
}
}
void heapSort(int arr[],int root,int length){
for(int i=length;i>root;i--){
MaxHeapAdject(arr, root, i);
myArray[0]=0;
swap(arr[root], arr[i]);
}
arrayPrint(arr, root, root+length);
}
void Merge(int arr[],int s,int length,int e){
myArray[0]=0;
int mid = s+length/2,r=mid,i=0,start=s;
vector<int>help(length);
for(;i<length;i++){
if(s>=mid||r>=e)break;
if(arr[s]<arr[r])help[i]=arr[s++];
else help[i]=arr[r++];
}
if(s<mid)for(;s<mid;s++)help[i++]=arr[s];
if(r<e)for(;r<e;r++)help[i++]=arr[r];
for(int i=0;i<length;i++)arr[start+i]=help[i];
}
void MergeSort(int arr[],int s,int length){
for(int size=2;size<length*2;size*=2){
for(int i=s;i<s+length;i+=size)
Merge(arr, i, size,min(i+size,s+length));
}
arrayPrint(myArray, 1, 101);
}
int partition(int arr[],int low,int high){
int key = arr[low];
while(low<high) {
while(arr[high]>=key&&high>low)high--;
arr[low]=arr[high];
while(arr[low]<=key&&low<high)low++;
arr[high]=arr[low];
}
arr[low]=key;
return low;
}
void quickSort(int arr[],int low,int high){
if(low<high){
int p = partition(arr, low, high);
quickSort(arr, low, p-1);
quickSort(arr, p+1, high);
}
}
int main(){
//std::ios::sync_with_stdio(false);
for(int i=1;i<=100;i++)myArray[i]=rand()%200;
arrayPrint(myArray, 1, 101);
//heapSort(myArray, 1, 100);
//MergeSort(myArray, 1, 100);
quickSort(myArray, 1, 100);
arrayPrint(myArray, 1, 101);
return 0;
}