zoukankan      html  css  js  c++  java
  • deque_queue_list

    #include <iostream>
    #include <deque>//front push pop back push pop [] at()
    #include <queue>
    #include <stack>
    #include <list> //remove
    using namespace std;
    
    void listTest()
    {
        int iArray[]={1,2,3,4,5,3,3,3,3,3,6};
        list<int> listInt(iArray,iArray+11);
    
        list<int>::iterator it_list=listInt.begin();
        for (;it_list!=listInt.end();++it_list)
        {
            cout<<*it_list<<" ";
        }
        cout<<endl;
        cout<<"=============================="<<endl;
        int i;
        for(i=0;i<11;i++)// (i-=1;i>=0;--i)
        {
            listInt.push_front(iArray[i]);
        }
        ///////////////////////////////////////
    
        for(i=0;i<11;i++)//
        {
            listInt.pop_front();
        }
        //-----------------------------------
        cout<<"pop front:"<<endl;
        it_list=listInt.begin();
        for (;it_list!=listInt.end();++it_list)
        {
            cout<<*it_list<<" ";
        }
        cout<<endl;
        cout<<"=============================="<<endl;
        ////////////////////////////////////////////////
    
        
        for(i-=1;i>=0;--i)
        {
            listInt.push_front(iArray[i]);
        }
        
        cout<<"push front:"<<endl;
        it_list=listInt.begin();
        for (;it_list!=listInt.end();++it_list)
        {
            cout<<*it_list<<" ";
        }
        cout<<endl;
        cout<<"=============================="<<endl;
    
        
        for(i=0;i<11;i++)//
        {
            listInt.pop_back();
        }
        
        cout<<"pop back:"<<endl;
        it_list=listInt.begin();
        for (;it_list!=listInt.end();++it_list)
        {
            cout<<*it_list<<" ";
        }
        cout<<endl;
        cout<<"=============================="<<endl;
    
        
        listInt.remove(3);
        cout<<"remove 3:"<<endl;
        it_list=listInt.begin();
        for (;it_list!=listInt.end();++it_list)
        {
            cout<<*it_list<<" ";
        }
        cout<<endl;
    /*
    1 2 3 4 5 3 3 3 3 3 6
    ==============================
    pop front:
    1 2 3 4 5 3 3 3 3 3 6
    ==============================
    push front:
    1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6
    ==============================
    pop back:
    1 2 3 4 5 3 3 3 3 3 6
    ==============================
    remove 3:
    1 2 4 5 6
    Press any key to continue    
    */
    }
    
    
    void stackTest()
    {
        int iArray[]={1,2,3,4,5,3,3,3,3,3,6};
        //stack<int> stackInt(iArray,iArray+11);
        stack<int> stackInt;
        for (int i=0;i<sizeof(iArray)/sizeof(int);i++)
        {
            stackInt.push(iArray[i]);
        }
    
        cout<<"pop~:"<<endl;
        int len=stackInt.size();
        for (i=0;i<len;i++)
        {
            cout<<stackInt.top()<<" ";
            stackInt.pop();
        }
        cout<<endl;
    /*
    pop~:
    6 3 3 3 3 3 5 4 3 2 1
    Press any key to continue    
        */
    }
    
    
    void queueTest()
    { 
        int iArray[]={1,2,3,4,5,3,3,3,3,3,6};
        //queue<int> queueInt(iArray,iArray+11);
        queue<int> queueInt;
        for (int i=0;i<11;i++)
        {
            queueInt.push(iArray[i]);
        }
        //queue<int>::iterator it_queue=queueInt.begin();
        //cout<<queueInt.end()<<endl;
        ////////////////////////////////
        cout<<"pop~:"<<endl;
        int len=queueInt.size();
        for (i=0;i<len;i++)
        {
            cout<<queueInt.front()<<" ";
            queueInt.pop();
        }
        cout<<endl;
    /*
    pop~:
    1 2 3 4 5 3 3 3 3 3 6
    Press any key to continue
    */
    }
    
    void main()
    {
        listTest();return;
        //stackTest();return;
        //queueTest();return;
        int iArray[]={1,2,3,4,5,3,3,3,3,3,6};
        //deque<int> deInt(iArray,iArray+11);
        deque<int> deInt;
        for (int i=0;i<11;i++)
        {
            deInt.push_back(iArray[i]);
        }
        
        deque<int>::iterator itorDeque=deInt.begin();
        for (;itorDeque!=deInt.end();++itorDeque)
        {
            cout<<*itorDeque<<" ";
        }
        cout<<endl;
        cout<<"=============================="<<endl;
        for(i=0;i<11;i++)// (i-=1;i>=0;--i)
        {
            deInt.push_front(iArray[i]);
        }
        for(i=0;i<11;i++)//
        {
            deInt.pop_front();
        }
        itorDeque=deInt.begin();
        for (;itorDeque!=deInt.end();++itorDeque)
        {
            cout<<*itorDeque<<" ";
        }
        cout<<endl;
    
        for(i-=1;i>=0;--i)
        {
            deInt.push_front(iArray[i]);
        }
    
        cout<<"push front:"<<endl;
        itorDeque=deInt.begin();
        for (;itorDeque!=deInt.end();++itorDeque)
        {
            cout<<*itorDeque<<" ";
        }
        cout<<endl;
    
        for(i=0;i<11;i++)//
        {
            deInt.pop_back();
        }
    
        cout<<"pop back:"<<endl;
        itorDeque=deInt.begin();
        for (;itorDeque!=deInt.end();++itorDeque)
        {
            cout<<*itorDeque<<" ";
        }
        cout<<endl;
    
        deInt.push_front(0);
        cout<<"at:"<<endl;
        for (i=0;i<deInt.size();i++)
        {
            cout<<deInt.at(i)<<" ";
        }
        cout<<endl;
    /*
    1 2 3 4 5 3 3 3 3 3 6
    ==============================
    1 2 3 4 5 3 3 3 3 3 6
    push front:
    1 2 3 4 5 3 3 3 3 3 6 1 2 3 4 5 3 3 3 3 3 6
    pop back:
    1 2 3 4 5 3 3 3 3 3 6
    at:
    0 1 2 3 4 5 3 3 3 3 3 6
    Press any key to continue
    */
    
    }
  • 相关阅读:
    公用表表达式(CTE)的递归调用
    c# 如何让tooltip显示文字换行
    实战 SQL Server 2008 数据库误删除数据的恢复
    SQL SERVER数据库中 是否可以对视图进行修改删除
    asp.net中实现文件批量上传
    sql server 2008学习2 文件和文件组
    sql server 2008学习3 表组织和索引组织
    sql server 2008学习4 设计索引的建议
    sql server 2008学习10 存储过程
    .net 调用 sql server 自定义函数,并输出返回值
  • 原文地址:https://www.cnblogs.com/sky20080101/p/6403032.html
Copyright © 2011-2022 走看看