这段代码怎样改错void Headadjust(SStablel& S, int s, int m) { //分数堆排序 Elemtype rc; rc = S.R[s]; for (int j = 2 * s; j <= m; j *= 2) { if (j < m && S.R[j].score < S.R[j + 1].score)++j; if (rc.score >= S.R[j].score) break; S.R[s] = S.R[j]; s = j; } } void Creatheap(SStablel& S) { int n = S.length; for (int i = n / 2; i > 0; --i) Headadjust(S, i, n); } void Headsort(SStablel& S) { Creatheap(S); for (int i = S.length; i > 1; --i) { Elemtype x; x = S.R[1]; S.R[1] = S.R[i]; S.R[i] = x; Headadjust(S, 1, i - 1); } } void Merge(Elemtype r[], Elemtype t[], int low, int mid, int high) { //分数归并排序 int i = low; int j = mid + 1; int k = low; while (i <= mid && j <= high) { if (r[i].score <= r[j].score) t[k++] = r[i++]; else t[k++] = r[j++]; } while (i <= mid) t[k++] = r[i++]; while (j <= high)t[k++] = r[j++]; } void Msort(Elemtype r[], Elemtype t[], int low, int high) { Elemtype s[1]; if (high == low)t[low] = r[low]; else { int mid = (high + low) / 2; Msort(r, s, low, high); Msort(r, s, mid + 1, high); Merge(s, t, low, mid, high); } } void Mergesort(SStablel& S) { Msort(S.R, S.R, 1, S.length); }
时间: 2024-03-25 14:37:15 浏览: 47
计算机考研/工作必会100题
在这段代码中,有两个函数名拼写错误,应该将 `SStablel` 改为 `SStable`,这可能是由于其他地方的拼写错误导致的。此外,代码中的 `Elemtype` 类型在没有给出定义的情况下使用,需要在代码开头或其他地方给出定义。
修改后的代码如下:
```
void Heapadjust(SStable& S, int s, int m) { //分数堆排序
Elemtype rc;
rc = S.R[s];
for (int j = 2 * s; j <= m; j *= 2) {
if (j < m && S.R[j].score < S.R[j + 1].score)++j;
if (rc.score >= S.R[j].score) break;
S.R[s] = S.R[j];
s = j;
}
}
void Createheap(SStable& S) {
int n = S.length;
for (int i = n / 2; i > 0; --i)
Heapadjust(S, i, n);
}
void Heapsort(SStable& S) {
Createheap(S);
for (int i = S.length; i > 1; --i) {
Elemtype x;
x = S.R[1];
S.R[1] = S.R[i];
S.R[i] = x;
Heapadjust(S, 1, i - 1);
}
}
void Merge(Elemtype r[], Elemtype t[], int low, int mid, int high) { //分数归并排序
int i = low;
int j = mid + 1;
int k = low;
while (i <= mid && j <= high) {
if (r[i].score <= r[j].score) t[k++] = r[i++];
else t[k++] = r[j++];
}
while (i <= mid) t[k++] = r[i++];
while (j <= high)t[k++] = r[j++];
}
void Msort(Elemtype r[], Elemtype t[], int low, int high) {
Elemtype s[1];
if (high == low)t[low] = r[low];
else {
int mid = (high + low) / 2;
Msort(r, s, low, high);
Msort(r, s, mid + 1, high);
Merge(s, t, low, mid, high);
}
}
void Mergesort(SStable& S) {
Msort(S.R, S.R, 1, S.length);
}
```
阅读全文