zoukankan      html  css  js  c++  java
  • 堆栈和队列

    // 堆栈.cpp : 定义控制台应用程序的入口点。
    //一种数据结构
    //堆栈中的元素遵循后进先出的原则(LIFO)后入栈的元素先出栈
    //队列
    //队列中的元素遵循先进先出的原则,先进队列的元素先出队列

    //stack  堆栈 适配器容器  是由其他容器实现的(可以指定由其它容器实现)
    /*
    push()压入堆栈
    pop()出栈
    top()栈顶元素
    size()大小(个数)
    */
    //queue  队列 适配器容器  是由其他容器实现的(可以指定由其它容器实现)
    /*
    push()加入队列
    front()取队头元素
    back()取队尾元素
    pop()出队列
    size()大小(个数)
    */
    #include "stdafx.h"
    #include<stack>
    #include<queue>
    #include<vector>
    #include<iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
     stack<int> stak;//stack<int,vector<int>> stak;
     stak.push(10);//入栈元素
     stak.push(20);//入栈元素
     int topValue = stak.top();//栈顶元素
     stak.pop();//出栈元素
     topValue = stak.top();
     cout << "***********************************" << endl;

     queue<int> que;
     que.push(12);
     que.push(13);
     que.push(14);
     int backvalue = que.back();//取队尾元素
     int frontvalue = que.front();//取对头元素
     cout << "队尾:"<<backvalue <<"队头:"<< frontvalue << endl;
     que.pop();//出队列一个元素
     backvalue = que.back();//取队尾元素
     frontvalue = que.front();//取对头元素
     cout << "队尾:" << backvalue << "队头:" << frontvalue << endl;
     int size = que.size();
     cout <<"元素大小:"<< size << endl;
     return 0;
    }

  • 相关阅读:
    HTTPS之acme.sh申请证书
    GoAccess日志分析工具
    KVM之CPU虚拟化
    自动化运维之PSSH
    Hadoop+HBase 集群搭建
    SSH + Google Authenticator 安全加固
    查看数据的类型(python)
    在word中,替换多个词语。正则表达式中 [] {} 是可以连用的(python)
    方差分析的前提,与检验,以及球形检验
    清屏处理(汇编)
  • 原文地址:https://www.cnblogs.com/rong123/p/7782985.html
Copyright © 2011-2022 走看看