Files
hello-algo/ja/codes/cpp/chapter_stack_and_queue/stack.cpp
Yudong Jin 7257641e0e 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
2026-10-30 02:12:26 +08:00

42 lines
1.0 KiB
C++

/**
* File: stack.cpp
* Created Time: 2022-11-28
* Author: qualifier1024 (2539244001@qq.com)
*/
#include "../utils/common.hpp"
/* 実行用コード */
int main() {
/* スタックを初期化する */
stack<int> stack;
/* 要素をプッシュする */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
cout << "スタック stack = ";
printStack(stack);
/* スタックの先頭要素にアクセスする */
int top = stack.top();
cout << "スタックの先頭要素 top = " << top << endl;
/* 要素をポップする */
stack.pop(); // 戻り値なし
cout << "ポップした要素 pop = " << top << "、ポップ後 stack = ";
printStack(stack);
/* スタックの長さを取得する */
int size = stack.size();
cout << "スタックの長さ size = " << size << endl;
/* 空かどうかを判定する */
bool empty = stack.empty();
cout << "スタックは空か = " << empty << endl;
return 0;
}