c++一个list,tuple的小例子

#include
#include
#include
#include
using namespace std;

int main()
{
	auto comp = [](auto& l, auto& r) {return std::get<0>(l) < std::get<0>(r); };
	vector<list<tuple<float, string>>>   vec;
	list<tuple<float, string>> List1;
	list<tuple<float, string>> List2;
	list<tuple<float, string>> List3;

	List1.emplace_back(1.0, "1.0");
	List1.emplace_back(2.0, "2.0");
	List1.emplace_back(1.5, "1.5");
	List1.emplace_back(1.2, "1.2");
	vec.push_back(List1);

	List2.emplace_back(1.1, "1.1");
	List2.emplace_back(2.1, "2.1");
	List2.emplace_back(1.3, "1.3");
	List2.emplace_back(1.4, "1.4");
	vec.push_back(List2);

	List3.emplace_back(1.7, "1.7");
	List3.emplace_back(1.6, "1.6");
	List3.emplace_back(0.9, "0.9");
	List3.emplace_back(2.4, "2.4");
	vec.push_back(List3);

	list<tuple<float, string>> merge_list = move(vec.front());
	merge_list.sort(comp);
	for (int i = 0; i < vec.size(); i++)
	{
		vec[i].sort(comp);
		merge_list.merge(move(vec[i]), comp);
	}
	list<tuple<float, string>>::iterator ptr = merge_list.begin();
	for (ptr; ptr != merge_list.end(); ptr++)
	{
		cout << get<0>(*ptr) << endl;
	}
	return 0;

}
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
2
2.1
2.4

作用: 将三个list的所有元素 根据大小关系整合到一个容器中

你可能感兴趣的:(cpp,c++,list,算法)