s*********g 发帖数: 849 | 1 What kind of data structure is "arr" in the following C function:
int insert (data_struct_t arr, int x)
{
int i,j,t;
if (arr.num >= arr.size)
return -1;
i = arr.num++;
arr.data[i] = x;
for (j = i >> 1; i; i = j) {
if (arr.data[i] > arr.data[j]) {
t = arr.data[i];
arr.data[i] = arr.data[j];
arr.data[j] = t;
j = j >> 1;
} else {
break;
}
}
return 0;
} | c*******d 发帖数: 255 | 2 应该是binary heap吧
【在 s*********g 的大作中提到】 : What kind of data structure is "arr" in the following C function: : int insert (data_struct_t arr, int x) : { : int i,j,t; : if (arr.num >= arr.size) : return -1; : i = arr.num++; : arr.data[i] = x; : for (j = i >> 1; i; i = j) { : if (arr.data[i] > arr.data[j]) {
| B*****t 发帖数: 335 | 3 complete binary max heap,
第一眼看成binary indexed tree了
【在 s*********g 的大作中提到】 : What kind of data structure is "arr" in the following C function: : int insert (data_struct_t arr, int x) : { : int i,j,t; : if (arr.num >= arr.size) : return -1; : i = arr.num++; : arr.data[i] = x; : for (j = i >> 1; i; i = j) { : if (arr.data[i] > arr.data[j]) {
|
|