c++ stl 已排序區間算法 合併連貫之排序區間inplace_merge使用方法

在這裏插入圖片描述

template<typename T>
inline void INSERT_ELEMENTS(T& coll, int first, int last)
{
	for (int i = first; i <= last; ++i)
	{
		coll.insert(coll.end(), i);
	}
}
template<typename T>
inline void PRINT_ELEMENTS(const T & coll, const string& optcstr = "")
{
	cout << optcstr;
	for (auto elem : coll)
	{
		cout << elem << ' ';
	}
	cout << endl;
}
int main()
{
	list<int>a;
	INSERT_ELEMENTS(a, 1, 7);
	INSERT_ELEMENTS(a, 1, 8);
	PRINT_ELEMENTS(a, "a: ");
	auto pos = find(a.begin(), a.end(), 7);
	++pos;
	inplace_merge(a.begin(), pos, a.end());
	PRINT_ELEMENTS(a, "a: ");

}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章