mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Several enhancements and fixes
This commit is contained in:
@ -78,7 +78,7 @@ class MaxHeap {
|
||||
}
|
||||
|
||||
/* 判断堆是否为空 */
|
||||
bool empty() {
|
||||
bool isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ class MaxHeap {
|
||||
/* 元素出堆 */
|
||||
void pop() {
|
||||
// 判空处理
|
||||
if (empty()) {
|
||||
if (isEmpty()) {
|
||||
throw out_of_range("堆为空");
|
||||
}
|
||||
// 交换根节点与最右叶节点(即交换首元素与尾元素)
|
||||
@ -149,7 +149,7 @@ int main() {
|
||||
cout << "\n堆元素数量为 " << size << endl;
|
||||
|
||||
/* 判断堆是否为空 */
|
||||
bool isEmpty = maxHeap.empty();
|
||||
bool isEmpty = maxHeap.isEmpty();
|
||||
cout << "\n堆是否为空 " << isEmpty << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user