list基本代码

#include<iostream>
#include<list>
//STL之list的基本用法 
using namespace std;
void outputList(list<int > lst)//it=head->next;it!=NULLL;it=it->next;
{
    
    list<int>::iterator it;LNode *it
    for(it=lst.begin();it!=lst.end();it++) 
    {
    if(it!=lst.begin())
        cout<<" ";
    cout<<*it;
    }
    cout<<endl;
}
 

int main()
{
    list<int>La;
    int i,m,n,t;
    cin>>n;
    
    for(i=0;i<n;i++)
    {
        cin>>t;
        La.push_back(t);//得到一个后进先出的链表 
        
     } 
     outputList(La);
     La.reverse();
      outputList(La);
     
     cin>>m;
     list<int>Lb;
     for(i=0;i<m;i++)
     {
         cin>>t;
         Lb.push_front(t);//得到一个先进先出的链表 
     }
     
     La.sort();//排序
     La.merge(Lb);//两个链表合并
     
     outputList(La);
     
     cout<<La.size()<<endl;//链表中有多少个节点 
     
     La.clear();
     
     return 0; 
     
     
      
}

 

转载于:https://www.cnblogs.com/ilovetheworld/p/10535639.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值