時才被接受我對我的代碼採用了Hoare分區方法有疑問。代碼錯誤 - 類名只有在註釋
這裏是僞代碼:(請糾正的東西,如果它是不正確的)
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
而且我的代碼:
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[] = {13, 19, 9, 5, 12, 8, 7, 4, 11, 2, 6, 21};
partition(a, 0, a.length-1);
}
}
和錯誤是:
error: Class names, 'Hoare', are only accepted if annotation
processing is explicitly requested
1 error
任何想法至於原因?
你的問題標籤不好,標題不好(你不希望幫助你使用分區算法來幫助調試),而且你的代碼格式不正確。 – Amichai 2010-06-01 20:22:38