Stack
1. push(value)
stack<string> stk;
stk.push("hello");
2. pop()
pop()의 반환형은 없다.
중요한 것은 스택이 empty 일 때, 런타임에러(Segmentation fault)가 발생한다.
stack<string> stk;
stk.pop();
3. top()
stack<string> stk;
stk.push("hello");
auto a = stk.top();
cout << a << '\n' << stk.top();
[출력]
hello
hello
4. size()
stack<string> stk;
cout << stk.size();
[출력]
0
5. empty()
스택이 비어있는지 확인하기 위해 사용할 수 있지만, ( size()==0 ) 과 의미와 사용법은 같다.
stack<string> stk;
stk.push("hello");
cout << stk.empty();
[출력]
1
Queue (큐)
1. push(value)
value를 큐에 추가한다.
2. pop()
front()의 값을 제거한다.
중요한 것은 큐가 empty 일 때, 런타임에러(Segmentation fault)가 발생한다.
3. front()
가장 앞에 있는 요소를 참조한다.
4. back()
가장 뒤에 있는 요소를 참조한다.
5. size()
큐의 크기를 반환한다.
6. empty()
큐가 비었으면 1, 그렇지 않으면 0 반환한다.
deque (덱)
1. push_front(value)
value를 덱의 Front에 추가한다.
2. push_back(value)
value를 덱의 Back에 추가한다.
3. pop_front()
Front의 값을 제거한다.
중요한 것은 덱이 empty 일 때, 런타임에러(Segmentation fault)가 발생한다.
4. pop_back()
Back의 값을 제거한다.
중요한 것은 덱이 empty 일 때, 런타임에러(Segmentation fault)가 발생한다.
5. front()
덱의 Front 값을 반환한다.
6. back()
덱의 Back 값을 반환한다.
7. size()
덱의 크기를 반환한다.
'C++' 카테고리의 다른 글
[C++] atoi(), stoi(), to_string() : int <-> string (0) | 2024.06.02 |
---|---|
[C++] 뒤집는 함수 : reverse() (0) | 2024.03.01 |
[C++] list 관련 함수 정리 : push_front(), insert(), erase(), pop_front(), front(), clear(), ... (0) | 2024.02.15 |
[C++] lower_bound()와 upper_bound() (0) | 2024.02.14 |
[C++] string 관련 함수 : insert(), erase(), find(), substr(), split(), ... (0) | 2024.02.13 |