There is a will there is a way!

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  4 随笔 :: 0 文章 :: 29 评论 :: 0 Trackbacks
文件  <stack>   <queue>   使用时stack<class T>  st  queue<class T>  q
stack   的使用方法有   push()的向容器顶部里插入元素, pop()是删除容器顶部的元素, top()返回容器顶部的元素,size()返回容器的元素个数,begin()是返回一个位于容器的第一个元素的迭代器,end()当然是最后了  empty()是检查是否为空的方法 空时返回true 否则返回 false,
queue 方法只有front()与 stack 不一样 当然是返回对头的元素,看看下面的例子吧.
#include<iostream>
#include
<stack>
#include
<queue>
using namespace std;
int main()
{
    stack
<int> st;
    queue
<int> q;
    st.push(
10);
    st.push(
20);
    q.push(
30);
    q.push(
40);
    cout
<<st.top()<<endl;
    st.pop();
    cout
<<st.top()<<endl;
    cout
<<q.front()<<endl;
    q.pop();
    cout
<<q.front()<<endl;
    
while(!st.empty())   //当然queue也能这样用
    {
       
int a=st.top();
       cout
<<a<<endl;
       st.pop();
    }
 
}


output:

20

10

30

40

10

 

posted on 2006-04-13 23:52 王直元 阅读(6721) 评论(11)  编辑 收藏 引用

评论

# re: 有关 C++的 stack queue 的使用 2006-04-14 09:41 Stone Jiang
generic progrmming 还是很有趣的.
多来些demo吧:)
  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2006-06-05 15:16 lelenole
hao
thanks  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2006-09-20 08:46 王直元
大哥,我只是做个示范嘛,我又没有说你那去就能用。知道不永远不要抄写。要理解了自己写!  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用[未登录] 2009-03-18 20:13 sun
queue 容量的 上限是多少`????  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2010-05-07 16:54 CARRILLOJUDY
I had got a desire to make my company, but I did not earn enough of cash to do this. Thank goodness my mate recommended to utilize the <a href="http://lowest-rate-loans.com">loan</a>. So I took the short term loan and realized my old dream.   回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2010-05-19 19:35 custom thesis
Your very hot notes like this good post could be a base for thesis writing or custom dissertation and be utilized at example of thesis.   回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2010-05-24 19:34 essay writing
Oh my gosh! That is the cutest thing I've ever seen !!!! Very often to receive your Academic level you have to order online essays .  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2013-06-21 17:22 hx
有错误  回复  更多评论
  

# re: 有关 C++的 stack queue 的使用 2013-06-29 00:56 up here
Are you looking which service to choose for buying resume or where to obtain sample of cover letter and excellent CV writing? Or you just would like to buy resume from certified resume writers? Just contact Resume company.  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理