频道栏目
首页 > 资讯 > 其他 > 正文

cpp的STL之list

16-11-02        来源:[db:作者]  
收藏   我要投稿

特点就是个双向链表

基本操作

//
//  main.cpp
//  use_stl_list
//
//  Created by bikang on 16/10/28.
//  Copyright (c) 2016年 bikang. All rights reserved.
//

#include 
#include 
using namespace std;

void tlist();

bool sortFunc(const int &a,const int &b);


int main(int argc, const char * argv[]) {
    // insert code here...
    tlist();
    return 0;
}

void tlist(){

    //创建
    std::list l1;
    //插入
    l1.push_front(11);
    l1.push_front(21);
    l1.push_back(3);
    //大小
    cout << l1.size()<::iterator elem;
    for(elem=l1.begin();elem!=l1.end();++elem){
        cout << *elem <<",";
    }
    cout << endl;

    //其他插入
    list l2;
    l2.push_back(1111);
    l2.insert(l2.begin(), l1.begin(),l1.end());

    //删除
    l2.erase(l2.begin());
    //范围删除
    //l2.erase(l2.begin(),l2.end());

    l2.push_back(21);

    for(elem=l2.begin();elem!=l2.end();++elem){
        cout << *elem <<",";
    }
    cout << endl;
    //反转
    l2.reverse();

    for(elem=l2.begin();elem!=l2.end();++elem){
        cout << *elem <<",";
    }
    cout << endl;

    //排序
    l2.sort();

    for(elem=l2.begin();elem!=l2.end();++elem){
        cout << *elem <<",";
    }
    cout << endl;

    //根据排序函数排序
    l2.sort(sortFunc);

    for(elem=l2.begin();elem!=l2.end();++elem){
        cout << *elem <<",";
    }
    cout << endl;




}

bool sortFunc(const int &a,const int &b){
    return (a > b);
}
相关TAG标签
上一篇:hello Kotlin
下一篇:Spring轻量级容器控制反转与依赖注入
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站