list类的使用

您所在的位置:网站首页 怎么定义一个list list类的使用

list类的使用

2022-05-30 00:21| 来源: 网络整理| 查看: 265

的成员函数

empty()

判断

list

是否为空

if (cList.empty()) 

{ 

printf(“this list is empty”);

} 

4)

、用

list::iterator

得到指向

list

的指针

list::iterator charIterator; 

for(cIterator = cList.Begin();cIterator != cList.end();cIterator++) 

{ 

printf(“%c”, *cIterator);

} //

输出

list

中的所有对象

说明:

cList.Begin()

cList.end()

函数返回指向

list::iterator

的指针,

由于

list

采用链表结构,因此它不支持随机存取,因此不能用

cList.begin()+3

来指向

list

的第四个对象,

vector

deque

支持随机存取。

 

 

5

)、用

STL

的通用算法

count()

来统计

list

中的元素个数

int cNum; 

char ch = ’b’;

cNum = count(cList.Begin(), cList.end(), ch); //

统计

list

中的字符

b

的个数

说明:在使用

count()

函数之前必须加入

#include   

 

6

)、用

STL

的通用算法

count_if ()

来统计

list

中的元素个数

const char c(‘c’);

class IsC 

{ 

public: 

 bool operator() ( char& ch ) 

 { 

  return ch== c; 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3