### quicksort partition algorithm

I am trying to code a partition quicksort but the problem here is at the output is in an infinite loop:
the input : 4 3 5 7 2
the expected output : 2 3 4 5 7
but my output is infinite :
2 3 4 5 7
2 3 4 5 7
2 3 4 5 7
.
.
and so on

what is the solu ?

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 #include #include #include using namespace std; /* Head ends here */ void partition(vector ar) { int temp,j=ar.size()-1,i=1,k=0,turn = 0,on_off=1; do{ if(ar[j]=k;x--) { if(x!=0&&j!=k) {ar[x] = ar[x-1];} } k++; j--; ar[0] = temp; turn = 0; on_off = 0; } if(ar[j]>ar[k]&&turn==1&&on_off == 1) { j--; turn = 0; on_off = 0; } if(ar[i]=k;x--) { if(x!=0&&i!=k) {ar[x] = ar[x-1];} } k++; i++; ar[0] = temp; turn = 1; on_off = 0; } if(ar[i]>ar[k]&&turn==0&&on_off == 1) { i++; turn = 1; on_off = 0; } on_off = 1; for(int z = 0;z _ar; int _ar_size; cin >> _ar_size; for(int _ar_i=0; _ar_i<_ar_size; _ar_i++) { int _ar_tmp; cin >> _ar_tmp; _ar.push_back(_ar_tmp); } partition(_ar); return 0; }
Duplicate here: http://www.cplusplus.com/forum/general/109642/