Skip to content

Commit

Permalink
修改
Browse files Browse the repository at this point in the history
  • Loading branch information
arkingc committed Aug 9, 2018
1 parent 86e8f8d commit 3aaa47c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions 数据结构与算法/堆.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- 左子节点:2i+1
- 右子节点:2i+2

若包含`sz`个节点,则第一个非叶子节点的序号为`(sz - 2) / 2`

![](../pic/al-tree-2.png)

## 插入节点
Expand Down
5 changes: 1 addition & 4 deletions 数据结构与算法/排序.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void heapsort(Elem A[],int n)
********************************************/
template <class value>
void _push_heap(vector<value> &arr,int hole){
value v = arr[hole];
value v = arr[hole];//取出新元素,从而产生一个空洞
int parent = (hole - 1) / 2;
//建最大堆,如果建最小堆换成 arr[parent] > value
while(hole > 0 && arr[parent] < v){
Expand Down Expand Up @@ -397,9 +397,6 @@ template <class value>
void heap_sort(vector<value> &arr)
{
_make_heap(arr);
for(int num : arr)
cout << num << " ";
cout << endl;
for(int sz = arr.size();sz > 1;sz--)
_pop_heap(arr,sz);
}
Expand Down

0 comments on commit 3aaa47c

Please sign in to comment.