zoukankan      html  css  js  c++  java
  • STL

    常规容器里面就 栈 与 队列  不提供迭代器, 不持持随机访问

     1 #include<queue>
     2 #include<iostream>
     3 
     4 using namespace std;
     5 
     6 void test01()
     7 {
     8     queue<int> q1;
     9     q1.push(10);
    10     q1.push(20);
    11     q1.push(30);
    12     q1.push(40);
    13     q1.push(100);
    14     //   队尾       队首  【先进先出】
    15     //   ===============
    16     //   100 40 30 20 10
    17     //   ===============
    18     cout << " q1.front()  = " << q1.front() << endl;
    19     cout << " q1.back()  = " << q1.back() << endl;
    20     while (!q1.empty())
    21     {
    22         cout << q1.front() << " ";
    23         q1.pop();
    24     }
    25     cout << endl;
    26 }
    27 
    28 int main()
    29 {
    30     test01();
    31     return 1;
    32 }

    因为是先进先出【从队伍尾部进入,从队伍前面出来,就像排队一样】,所以每次打印的都是队首元素(front);

  • 相关阅读:
    yii分页
    ajax分页
    批删,全选
    网站开发的愿景
    margin collapse 坍塌
    URI URL URN
    Servlet
    Http请求
    进程间通信
    网络编程
  • 原文地址:https://www.cnblogs.com/winslam/p/9415271.html
Copyright © 2011-2022 走看看