I am new in C++. And for my first ever problem about Quick Sort algorithm, when I run the code, it wont stop asking for input. Even though i have been running the code from a different IDE the problem persists.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void swap(int &x, int &y){
int temp;
temp=x;
x=y;
y=temp;
}
void part(int *a, int lo, int hi){
if(lo<hi){
int p=lo;
int s=lo;
int e=hi;
while(s<e){
while(a[s]<=a[p]){
if(s!=hi+1){
s++;
}else{
s--;
}
}
cout<<s<<endl;
while(a[e]>a[p]){
e--;
}
cout<<e<<endl;
while(s<e){
swap(a[s], a[e]);
cout<<a[s]<<a[e];
}
}
swap(a[p], a[e]);
part(a, lo, e-1);
part(a, e+1, hi);
}
}
int main(){
int n;
cin>>n;
int *arr=new int[n];
for(int i=0; i<n; i++){
cin>>arr[i];
}"it wont go after this"
part(arr, 0, n-1);
for(int i=0; i<n; i++){
cout<<arr[i]<<" ";
}
return 0;
}
I am unable to get the answer. Hope you guys will help me out. Thanks in advance