#include<stdio.h>
#include<stack>
std::stack<int>S; //정수 스택 선언
int main()
{
for(int i=1; i<=3;i++) //정수 스택에 1, 2, 3 순서대로 삽입
S.push(i);
for(int i=1;i<=2;i++) //정수 스택 가장 위에 있는 값을 출력하며 제거 2회
{
printf("%d ", S.top());
S.pop();
}
printf("\n");
S.push(4); //4 삽입
S.push(5); //5삽입
while(!S.empty()) //모두 비워질 때까지 스택의 값을 출력하며 제거
{
printf("%d ", S.top());
S.pop();
}
printf("\n");
}
/*
3 2
5 4 1
--------------------------------
Process exited after 0.02178 seconds with return value 0
계속하려면 아무 키나 누르십시오 . . .
*/
댓글