Help us understand the problem. What is going on with this article?

C++コンテナ std::stack

More than 3 years have passed since last update.

std::stack

C++コンテナのうちの一つ.データを積み重ねるイメージで末尾挿入、末尾削除を行うことができる.

push()関数

push.cpp
stack<int> s;
s.push(0);
s.push(1);

トップに要素を挿入する.

pop()関数

pop.cpp
stack<int> s;
s.push(10);
s.push(20);
cout << s.top() << endl;  //20
s.pop();
cout << s.top() << endl;  //10

トップ要素を削除する.

empty()関数

empty.cpp
stack<int> s;
cout << s.empty() << endl;  //1
s.push(1);
cout << s.empty() << endl;  //0

空なら1,空でないなら0を返す.

size()関数

size.cpp
stack<int> s;
cout << s.size() << endl;  //0
s.push(0);
s.push(1);
cout << s.size() << endl;  //2

格納されている要素の個数を返す.

top()関数

top.cpp
stack<int> s;
s.push(10);
s.push(20);
cout << s.top() << endl;  //20

s.top -= 5;
cout << s.top() << endl;  //15

トップ要素にアクセスする.

サンプルコード

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした