mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-04 04:02:48 +08:00
Retranslate the complete Japanese online edition from Chinese (#2008)
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
This commit is contained in:
@@ -7,55 +7,55 @@
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
void testPush(priority_queue<int> &heap, int val) {
|
||||
heap.push(val); // 要素をヒープに追加
|
||||
cout << "\n要素 " << val << " をヒープに追加した後" << endl;
|
||||
heap.push(val); // ヒープに要素を挿入する
|
||||
cout << "\n要素 " << val << " をヒープに挿入した後" << endl;
|
||||
printHeap(heap);
|
||||
}
|
||||
|
||||
void testPop(priority_queue<int> &heap) {
|
||||
int val = heap.top();
|
||||
heap.pop();
|
||||
cout << "\nヒープ先頭要素 " << val << " を取り出した後" << endl;
|
||||
cout << "\nヒープの先頭要素 " << val << " を取り出した後" << endl;
|
||||
printHeap(heap);
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* 実行用コード */
|
||||
int main() {
|
||||
/* ヒープを初期化 */
|
||||
/* ヒープを初期化する */
|
||||
// 最小ヒープを初期化する
|
||||
// priority_queue<int, vector<int>, greater<int>> minHeap;
|
||||
// 最大ヒープを初期化する
|
||||
priority_queue<int, vector<int>, less<int>> maxHeap;
|
||||
|
||||
cout << "\n以下のテスト例は最大ヒープです" << endl;
|
||||
cout << "\n以下のテストケースは最大ヒープを対象とする" << endl;
|
||||
|
||||
/* 要素をヒープに追加 */
|
||||
/* ヒープに要素を挿入する */
|
||||
testPush(maxHeap, 1);
|
||||
testPush(maxHeap, 3);
|
||||
testPush(maxHeap, 2);
|
||||
testPush(maxHeap, 5);
|
||||
testPush(maxHeap, 4);
|
||||
|
||||
/* ヒープ頂点の要素を取得 */
|
||||
/* ヒープの先頭要素を取得する */
|
||||
int peek = maxHeap.top();
|
||||
cout << "\nヒープ先頭要素は " << peek << endl;
|
||||
cout << "\nヒープの先頭要素は " << peek << endl;
|
||||
|
||||
/* ヒープ頂点の要素を取り出す */
|
||||
/* ヒープの先頭要素を取り出す */
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
testPop(maxHeap);
|
||||
|
||||
/* ヒープのサイズを取得 */
|
||||
/* ヒープのサイズを取得する */
|
||||
int size = maxHeap.size();
|
||||
cout << "\nヒープ要素数は " << size << endl;
|
||||
cout << "\nヒープの要素数は " << size << endl;
|
||||
|
||||
/* ヒープが空かどうかを判定 */
|
||||
/* ヒープが空か判定 */
|
||||
bool isEmpty = maxHeap.empty();
|
||||
cout << "\nヒープが空かどうかは " << isEmpty << endl;
|
||||
cout << "\nヒープは空か " << isEmpty << endl;
|
||||
|
||||
/* リストを入力してヒープを構築 */
|
||||
/* リストを入力してヒープを構築する */
|
||||
// 時間計算量は O(n) であり、O(nlogn) ではない
|
||||
vector<int> input{1, 3, 2, 5, 4};
|
||||
priority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end());
|
||||
|
||||
Reference in New Issue
Block a user