Several enhancements and fixes

This commit is contained in:
krahets
2023-09-14 03:36:31 +08:00
parent a9d70e9e4b
commit d190dbf3c1
18 changed files with 84 additions and 70 deletions

View File

@ -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;