Stack

Minjun_·2022년 1월 16일

C++

목록 보기
1/5
post-thumbnail

Stack (C++ STL)

Stack이란?

한쪽 끝에서만 자료를 넣거나 뺄 수 있는 선형 LIFO(Last In First Out)구조.
제일 마지막에 넣은 데이터가 처음으로 빠져나온다.

stack

Stack Header file

#include <stack>

stack<int> stack;

Stack 기본 함수

  • push : stack에 데이터 추가

     stack.push(element);
    • Parameter : the value of the element to push
    • Return value : None
  • pop : stack에 데이터 삭제

    stack.pop();
    • Parameter : None
    • Return value : None
  • top : stack의 제일 위 데이터 반환

    stack.top();
    • Parameter : None
    • Return value : Reference to the last element
  • size : stack의 사이즈 반환

    stack.size();
    • Parameter : None
    • Return value : The number of elements in the container
  • empty : stack이 비었는지 확인

    stack.empty();
    • Parameter : None
    • Return value : true / false
  • swap : 두 스택의 내용 바꾸기 (C++ 11)

    stack1.swap(stack2);
    • Parameter : other
    • Return value : None

출처

profile
졸음을 이겨내자..!

0개의 댓글