hi,
kann mir jemand sagen ob ich denn Pseudocod richtig übersetzt haben und ob der Algorithmus richtig ist?
kann mir jemand sagen ob ich denn Pseudocod richtig übersetzt haben und ob der Algorithmus richtig ist?
ComparisonCounting-Sort(A[0::n - 1])
1 for i = 0 to n 1
2 Count[i ] = 0
3 for i = 0 to n 2
4 for j = 0 to n 1
5 if A[i ] < A[j ]
6 Count[j ] = Count[j + 1 ]
7 else
8 Count[i ] = Count[i + 1 ]
9 for i = 0 to n 1
10 S[Count[i ]] = A[i ]
11 return S
Code:
public static int[] ccsA2(int a[]) {
int Count[] = new int[a.length+1];
for (int i = 0; i <= a.length - 1; i++) {
Count[i] = 0;// jede stelle des array eine 0
}
for (int i = 0; i <= a.length - 2; i++) {// test[]={2,1,5,6,3,4};6
for (int j = 0; j <= a.length - 1; j++) {
if (a[i] < a[j]) {
Count[j] = Count[j]+1;
} else {
Count[i] = Count[i + 1];
}
}
}
int s[] = new int[a.length - 1];
for (int i = 0; i <= a.length - 1; i++) {
s[Count[i]] = a[i];
}
return s;
}