프로그래밍/자료구조와 알고리즘

stack

우대비 2022. 11. 13. 10:20
반응형

stack - 선입후출

 

선입후출이라 하면 프링글스 통을 생각하면 됨

가장 먼저 들어간 놈이 가장 안쪽에 있게 되므로

가장 나중에 먹게됨!

 

stack안의 대표적인 기능들

stack<char> sc;
char a = '';

// stack에 데이터를 밀어넣음
sc.push(a);

// stack 가장 위에 있는 데이터를 꺼냄
char a = sc.top();

// stack 가장 위에 있는 데이터를 삭제
sc.pop();

// stack이 비어있는지 체크
sc.empty();

// stack안에 몇개의 데이터가 쌓였는지 확인
sc.size();

 

stack 활용 예제

 

[ C++ ] 단어 뒤집기 - 9093

- Stack 사용x #include #include #include using namespace std; string RvsWord(string& str) { int size = str.length(); string c; int cp = 0; // 체크포인트 bool isRvs = false; // 후진 합니까? for (int i = 0; i < size;) { if (isRvs == false) // 후

flrjtwjrjt.tistory.com

 

 

[C++] 스택 - 10828

#include #include using namespace std; class Stack { public: void push(int x) { t[++_top] = x; } void pop() { if (_top >= 0) _top--; return; } int size() { return _top + 1; } bool empty() { if (_top == -1) return true; return false; } int top() { if (_top

flrjtwjrjt.tistory.com

 

반응형
LIST