码迷,mamicode.com
首页 > 其他好文 > 详细

set容器

时间:2019-04-08 00:49:45      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:自身   结构   name   1.2   class   success   col   二叉树   return   

简介:先进先出

1.1 是关联式容器,自身是有规则,会进行排序,默认排序升序

1.2 数据结构是二叉树,迭代器是双向

1.3 set容器键值不允许相同

1.4 查找速度很快,有排序需求和查找速度需求,用set容器来存储数据

void test01()
{
    queue<int> q;
    q.push(10);
    q.push(20);
    q.push(30);
    q.push(40);
    q.push(50);

    cout << q.front() << endl;
    cout << q.back() << endl;
    cout << endl;
    while (!q.empty())
    {
        cout << q.front() << endl;
        q.pop();
    }
    
    cout << "size:" << q.size() << endl;

}

//2.存储对象
class Maker
{
public:
    Maker(string name, int age)
    {
        this->name = name;
        this->age = age;
    }
public:
    string name;
    int age;
};

void test02()
{
    queue<Maker> q;
    q.push(Maker("aaa1", 10));
    q.push(Maker("aaa2", 20));
    q.push(Maker("aaa3", 30));

    cout << q.front().name<<" "<<q.front().age << endl;
    cout << q.back().name<<" " <<q.back().age<< endl;
    cout << endl;
    while (!q.empty())
    {
        cout << q.front().name << " " << q.front().age << endl;
        q.pop();
    }

    cout << "size:" << q.size() << endl;
}

int main()
{
    test02();
    system("pause");
    return EXIT_SUCCESS;
}

 

set容器

标签:自身   结构   name   1.2   class   success   col   二叉树   return   

原文地址:https://www.cnblogs.com/kony9527/p/10655844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!