반응형
스택(Stack)
가장 마지막에 들어온 Data가 가장 먼저 처리되는 후입선출(Last In First Out, LIFO), 선입후출(First In Last Out, FILO) 자료구조
Stack 동작 Sequnce
더보기

삽입 7

삽입 5

삽입 4

삭제

삽입 6

삭제
명령: 삽입 (7) → 삽입(5) → 삽입(4) → 삭제() → 삽입(6) → 삭제()






Code
#include <iostream>
#include <stack>
using namespace std;
int main(void){
stack<int> s;
s.push(7);
s.push(5);
s.push(4);
s.pop();
s.push(6);
s.pop();
while(!s.empty()){
cout << s.top() << " ";
s.pop();
}
return 0;
}
출력
5 7
반응형
'Algorithm' 카테고리의 다른 글
[Algorithm] 너비 우선 탐색(BFS, Breadth First Search) (0) | 2023.04.09 |
---|---|
[Algorithm] 큐(Queue) (0) | 2023.04.09 |
[Algorithm] 심화 정렬 문제 (0) | 2023.04.09 |
[Algorithm] 계수 정렬(Counting Sort) (0) | 2023.04.09 |
[Algorithm] 힙 정렬(Heap Sort) (0) | 2023.04.09 |