STL--queue

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
    struct Info
    {
        string name;
        int  score;
    bool operator  < (const Info &a) const
    {
        return a.score<score;
    }
    };
int main(int argc, char* argv[])
{
    queue<int> q;
    q.push(2);
    q.push(4);
    q.push(8);
    q.push(1);
    cout<<q.size()<<endl;
    cout<<q.empty()<<endl;
    cout<<q.front()<<endl;
    cout<<q.back()<<endl;
    while(q.empty()!=true)
    {
        cout<<q.front()<<' ';
        q.pop();
    }
    cout<<endl<<"_________________________________________"<<endl;

    priority_queue<int> pq;
    pq.push(2);
    pq.push(4);
    pq.push(8);
    pq.push(1);
    cout<<pq.size()<<endl;
    while(pq.empty()!=true)
    {
        cout<<pq.top()<<' ';
        pq.pop();
    }
    cout<<endl;

    priority_queue <Info> m1;
    Info info;
    info.name="Jack";
    info.score=60;
    m1.push(info);
    info.name="Peter";
    info.score=80;
    m1.push(info);
    info.name="Marry";
    info.score=100;
    m1.push(info);
    while(!m1.empty())
    {
        cout<<m1.top().name<< ' '<<m1.top().score<<endl;
        m1.pop();
    }



    return 0;
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenyuk1/article/details/51545058
个人分类: 自习
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭