question about partition
Posted
by davit-datuashvili
on Stack Overflow
See other posts from Stack Overflow
or by davit-datuashvili
Published on 2010-06-01T20:16:10Z
Indexed on
2010/06/01
20:43 UTC
Read the original article
Hit count: 160
algorithm
|possible-homework
i have question about hoare partition method here is code
and also pseudo code please if something is wrong correct
pseudo code
HOARE-PARTITION ( A, p, r)
1 x ? A[ p]
2 i ? p-1
3 j ? r +1
4 while TRUE
5 do repeat j ? j - 1
6 until A[ j ] = x
7 do repeat i ? i + 1
8 until A[i] = x
9 if i < j
10 then exchange A[i] ? A[ j ]
11 else return j
and my code
public class Hoare {
public static int partition(int a[],int p,int r) {
int x=a[p];
int i=p-1;
int j=r+1;
while (true) {
do
{
j=j-1;
} while(a[j]>=x);
do
{
i=i+1;
} while(a[i]<=x);
if (i<j) {
int t=a[i];
a[i]=a[j];
a[j]=t;
} else {
return j;
}
}
}
public static void main(String[]args){
int a[]=new int[]{13,19,9,5,12,8,7,4,11,2,6,21};
partition(a,0,a.length-1);
}
}
and mistake is this error: Class names, 'Hoare', are only accepted if annotation processing is explicitly requested 1 error any ideas
© Stack Overflow or respective owner