C++ list 翻转与排序

# include<iostream>
# include<list>
using namespace std;


bool myCompare(int v1,int v2)
{
	//降序 第一个数大于第二个数
	return v1 > v2;

}
void printList(const list<int>& L)
{
	for (list<int>::const_iterator it = L.begin(); it != L.end(); it++)
	{
		cout << *it << " ";

	}
	cout << endl;
}
void test01()
{

	//所有不支持随机访问迭代器的容器,不可以使用标准算法
	//不支持随机访问迭代器的容器,内部会供应对应的一些算法
	list<int>L1; //默认构造
	L1.push_back(10);
	L1.push_back(20);
	L1.push_back(30);
	L1.push_front(40);
	L1.push_front(50);
	printList(L1);
	L1.reverse();
	printList(L1);
	L1.sort(myCompare);
	printList(L1);
}

int main()
{
	test01();
	system("pause");
	return 0;
}
全部评论

相关推荐

LZStarV:冲就好了,就算真的是字节也冲,面评脏了大不了等三四个月就淡了,而且等到那个时候实力进步了选择还多,何必拘泥于字节
点赞 评论 收藏
分享
10-22 19:44
门头沟学院 Java
面了100年面试不知...:那我得去剪个头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务