voidAjustHeap(int* arr, int node, int n){ int left = node * 2 + 1; int right = node * 2 + 2; int max_pos = node; if (left < n && arr[left] > arr[max_pos]) max_pos = left; if (right < n && arr[right] > arr[max_pos]) max_pos = right; if (max_pos != node){ swap(arr[max_pos], arr[node]); AjustHeap(arr, max_pos, n); } }
近期评论