STL(十八)stack堆栈容器

xiaoxiao2021-02-28  76

一、stack技术原理

       

二、stack应用基础

#include <stack>

1、创建stack对象

       stack()

       stack(const  stack &)

2、元素入栈

       push(const  value_type  &x)

3、元素出栈

       void  pop()

4、取栈顶元素

       value_type&   top()

5、堆栈非空判断

       bool    empty()

6、堆栈的大小

       size_type   size()

#include <stack> #include <list> #include <iostream> #define STACK_SIZE 100 int main(void) { using namespace std; stack<int, list<int> > s; // if (s.size() < STACK_SIZE) s.push(68); if (s.size() < STACK_SIZE) s.push(1); if (s.size() < STACK_SIZE) s.push(17); // while (!s.empty()) { cout << s.top() << endl; s.pop(); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-96600.html

最新回复(0)