List使用
来源:互联网 发布:超兽武装玩具淘宝 编辑:程序博客网 时间:2024/05/18 00:31
#pragma once
class TestList
{
//适用于插入和删除操作, remove用来删除逻辑元素, erase用来删除物理元素。 remove速度快,但陷井较多。 erase速度慢,但陷井少
public:
TestList(void);
virtual ~TestList(void);
void test();
void test1();
void test2();
};
//---------------------------------------------------------
#include "TestList.h"
#include <list>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
TestList::TestList(void)
{
}
TestList::~TestList(void)
{
}
void TestList::test()
{
list<char> coll;
for(char c='a'; c<='z'; ++c)
{
coll.push_back(c);
}
copy(coll.begin(),coll.end(),ostream_iterator<char>(cout," "));
cout<<endl;
}
void TestList::test1()
{
list<char> coll;
for(char c='a'; c<='z'; ++c)
{
coll.push_back(c);
}
list<char>::const_iterator pos;
for( pos = coll.begin(); pos != coll.end(); ++pos)
{
cout<<*pos<<' ';
}
cout<<endl;
}
void TestList::test2()
{
list<int> coll;
for(int i=1; i<=6; ++i)
{
coll.push_front(i);
coll.push_back(i);
}
cout<<"pre: "<<endl;
copy(coll.begin(),coll.end(),ostream_iterator<int>(cout," "));
cout<<endl;
list<int>::iterator endLogic = remove(coll.begin(),coll.end(),3);
cout<<"real: remove: "<<endl;
copy(coll.begin(),coll.end(),ostream_iterator<int>(cout," "));
cout<<endl;
cout<<"logic: remove"<<endl;
copy(coll.begin(),endLogic,ostream_iterator<int>(cout," "));
cout<<endl;
coll.erase(endLogic,coll.end());
cout<<"real: erase"<<endl;
copy(coll.begin(),coll.end(),ostream_iterator<int>(cout," "));
cout<<endl;
}
- list使用
- List使用
- List使用
- 正确使用List.toArray()
- c#2.0 List 使用
- List Control 基本使用
- 泛型List使用示例
- 泛型List使用示例
- Dictionary List类使用
- Python 之 list 使用
- 使用List类实例
- STL list使用心得
- List box的使用
- list的使用
- 有关List的使用
- stl list.remove_if使用
- list unique使用
- lwuit-List控件使用
- VBA语句集100句(第2辑)
- 汇编 C语言 C++语言
- Excel VBA程序的编写
- VBA程序集(第3辑)
- 回调函数的抽象理论
- List使用
- 自己写的代码:时钟
- win7下安装ubuntu失败,无法安装系统----解决
- 《汇编语言》 习题1 理解出问题啦
- PE Loader
- VBA程序集(第2辑)
- 驱动开发 常用字符串操作函数
- 所谓容器
- VBA程序集(第1辑)