following code for partition
#include<iostream>
using namespace std;
#define maxn 10000
int x[maxn];
void partition(int x[],int p,int r){
int y=x[p];
int i=p-1;
int j=r+1;
while(i<j){
do{
j=j-1;
} while( x[j]>y);
do
{
i=i+1;
} while(x[j]<y);
if (i<j){ int s=x[i];x[i]=x[j];x[j]=s; }
if (i>=j) break;
}
}
int main(){
int n=12;
for (int i=1;i<=n;i++) cin >>x[i];
partition(x,1,n);
for (int i=1;i<=n;i++) cout<<x[i]<<" ";
return 0;
}
does not work,it means that when i enter some numbers,and press enter it does not worite anything,neither partitioned array of course,please help me
I don`t really what are you trying but may be second while comparison:
must be changed by