From 6ca5fa7d93287e39ac97b94236f48080cbb2ef3b Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Sat, 4 Feb 2023 14:41:31 +0800 Subject: [PATCH] Update heap.cpp --- codes/cpp/chapter_heap/heap.cpp | 12 ++++++------ codes/cpp/include/PrintUtil.hpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/codes/cpp/chapter_heap/heap.cpp b/codes/cpp/chapter_heap/heap.cpp index 38171c8d3..8d32d17ff 100644 --- a/codes/cpp/chapter_heap/heap.cpp +++ b/codes/cpp/chapter_heap/heap.cpp @@ -9,14 +9,14 @@ void testPush(priority_queue &heap, int val) { heap.push(val); // 元素入堆 - cout << "元素 " << val << " 入堆后" << endl; + cout << "\n元素 " << val << " 入堆后" << endl; PrintUtil::printHeap(heap); } void testPoll(priority_queue &heap) { int val = heap.top(); heap.pop(); - cout << "堆顶元素 " << val << " 出堆后" << endl; + cout << "\n堆顶元素 " << val << " 出堆后" << endl; PrintUtil::printHeap(heap); } @@ -28,7 +28,7 @@ int main() // 初始化大顶堆 priority_queue, less> maxHeap; - cout << "以下测试样例为大顶堆" << endl; + cout << "\n以下测试样例为大顶堆" << endl; /* 元素入堆 */ testPush(maxHeap, 1); @@ -39,7 +39,7 @@ int main() /* 获取堆顶元素 */ int peek = maxHeap.top(); - cout << "堆顶元素为: " << peek << endl; + cout << "\n堆顶元素为 " << peek << endl; /* 堆顶元素出堆 */ testPoll(maxHeap); @@ -50,11 +50,11 @@ int main() /* 获取堆大小 */ int size = maxHeap.size(); - cout << "堆元素数量为: " << size << endl; + cout << "\n堆元素数量为 " << size << endl; /* 判断堆是否为空 */ bool isEmpty = maxHeap.empty(); - cout << "堆是否为空: " << isEmpty << endl; + cout << "\n堆是否为空 " << isEmpty << endl; /* 输入列表并建堆 */ // 时间复杂度为 O(n) ,而非 O(nlogn) diff --git a/codes/cpp/include/PrintUtil.hpp b/codes/cpp/include/PrintUtil.hpp index 56583e15b..cd878e5ab 100644 --- a/codes/cpp/include/PrintUtil.hpp +++ b/codes/cpp/include/PrintUtil.hpp @@ -326,7 +326,7 @@ class PrintUtil { template static void printHeap(priority_queue &heap) { vector vec = Container(heap); - cout << "堆的数组表示:" << endl; + cout << "堆的数组表示:"; printVector(vec); cout << "堆的树状表示:" << endl; TreeNode *root = vecToTree(vec);