stack和queue常用方法

来源:互联网 发布:电脑看电视直播软件 编辑:程序博客网 时间:2024/05/21 22:39

stack常用方法

empty() 是否为空
size() 元素个数
pop() 删除栈顶元素
top() 返回栈顶元素的值
push() 增加元素

stack<string> st;   st.push("hello");   st.push("richard");   st.push("yang");   cout<<"the stack size is "<<st.size()<<endl;   while(!st.empty()){     cout<<st.top()<<endl;     st.pop();   }

queue常用方法

empty() 是否为空
size() 元素个数
pop() 删除栈顶元素
top() 返回队头元素的值
push() 增加元素
front()返回队头元素的值

 queue<string> que;  que.push("hello");  que.push("richard");  que.push("yang");  cout<<"the size of queue is "<<que.size()<<endl;  while(!que.empty()) {    cout<<que.front()<<endl;    cout<<que.back()<<endl;    que.pop();  }
0 0
原创粉丝点击