Chinaunix首页 | 论坛 | 博客
  • 博客访问: 89260
  • 博文数量: 34
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 395
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 10:22
文章分类

全部博文(34)

文章存档

2011年(1)

2010年(4)

2009年(29)

我的朋友

分类: C/C++

2009-05-07 23:41:31

 
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
int main()
{
 list intList1,intList2,intList3,intList4;
 ostream_iterator screen(cout," ");
 //迭代器输出元素以空格为间隔
 intList1.push_back(10);
 for(int i=0;i<10;i++)
  intList1.push_back(10+i);
 cout<<"intList1:"< copy(intList1.begin(),intList1.end(),screen);
 cout<
 intList2=intList1;
 cout<<"intList2:"< copy(intList2.begin (),intList2.end (),screen);
 cout<
 intList1.unique ();//删除连续的重复项
 cout<<"After removing the consecutive duplicates,"<<" intList1:"< copy(intList1.begin (),intList1.end(),screen);
 cout<
 intList1.push_back (5);
 cout<<"After push_back(5):"< copy(intList1.begin(),intList1.end(),screen);
 cout<
 intList1.sort ();
 cout<<"After sorting:"< copy(intList1.begin(),intList1.end(),screen);
 cout<
 intList3.push_back (13);
 intList3.push_back (23);
 intList3.push_back (25);
 intList3.push_back (136);
 intList3.push_back (198);
 intList3.push_back (89);
 intList3.push_back (45);
 cout<<"intList3:"< copy(intList3.begin(),intList3.end(),screen);
 cout<
 intList4.push_back (-2);
 intList4.push_back (-7);
 intList4.push_back (-8);
 intList4.push_back (-36);
 cout<<"intList4:"< copy(intList4.begin(),intList4.end(),screen);
 cout<
 intList3.splice (intList3.begin (),intList4);
 cout<<"After moving the elements of intList4 into intList3, intList3:"< copy(intList3.begin(),intList3.end(),screen);
 cout<
 intList3.sort ();
 cout<<"After sorting,intList3:"< copy(intList3.begin(),intList3.end(),screen);
 cout<
 intList1.merge (intList3);
 cout<<"After merging intList1 and intList3,intList1:"< copy(intList1.begin(),intList1.end(),screen);
 cout<
 intList1.unique ();
 cout<<"After unique(),intList1:"< copy(intList1.begin(),intList1.end(),screen);
 cout<
 return 0;
}
运行结果:
 
 
阅读(817) | 评论(0) | 转发(0) |
0

上一篇:双向链表ADT实现

下一篇:递归应用举例

给主人留下些什么吧!~~