std::list 一些函数简介(merge)

// list::merge
//如果合并的 两个链表是有序的那么合并之后也是有序的
//强调特别在vs10下合并的链表必须是有序的
#include
#include
// compare only integral part:
bool mycomparison (double first, double second)
{ return ( int(first)

int main ()
{
std::list first, second;


first.push_back (3.1);
first.push_back (2.2);
first.push_back (2.9);


second.push_back (3.7);
second.push_back (7.1);
second.push_back (1.4);


  first.sort();
  second.sort();


first.merge(second);

// (second is now empty)
second.push_back(1.3);
first.merge(second);
std::cout << "first contains:";
for (std::list::iterator it=first.begin(); it!=first.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';


system("pause");
return 0;
}

你可能感兴趣的:(std::list 一些函数简介(merge))