C++list操作

#include 
#include 
#include
using namespace std;
template 
bool SortPredicate_Descending(const int& lsh, const int& rsh)
{
 return(lsh > rsh);
}
void DisplayVector(const T& vecInput)
{
 for (auto iElement = vecInput.cbegin(); iElement != vecInput.cend();
 ++iElement)
 {
  cout << *iElement << " ";
  cout << endl;
 }
}
int main()
{
 //list  listIntegers1;
 //listIntegers1.insert(listIntegers1.begin(), 2);
 //listIntegers1.insert(listIntegers1.begin(), 1);
 //listIntegers1.insert(listIntegers1.end(), 3);
 //cout << "the contents of list 1 after inserting elements:" << endl;
 //DisplayVector(listIntegers1);
 //list  listIntegers2;
 //listIntegers2.insert(listIntegers2.begin(), 4, 0);
 //cout << "the contents of list 2 after inserting";
 //cout << listIntegers2.size() << "elements of a value" << endl;
 //DisplayVector(listIntegers2);
 //list  listIntegers3;
 //listIntegers3.insert(listIntegers3.begin(), listIntegers1.begin(), listIntegers1.end());
 //cout << "the contents of list 3 after inserting the contents";
 //cout << "list 1 at the beginning:" << endl;
 //DisplayVector(listIntegers3);
 //listIntegers3.insert(listIntegers3.end(), listIntegers2.begin(), listIntegers2.end());
 //cout << "the contents of list 3 after inserting";
 //DisplayVector(listIntegers3);
 //list  listIntegers;
 //listIntegers.push_back(4);
 //listIntegers.push_back(3);
 //listIntegers.push_back(5);
 //listIntegers.push_back(2);
 //auto iValue2 = listIntegers.insert(listIntegers.begin(), 2);
 //cout << "Initial contents of the list:" << endl;
 //DisplayVector(listIntegers);
 //listIntegers.erase(listIntegers.begin(), iValue2); //删除指定范围的元素
 //cout << "Contents after erasing a range of elements:" << endl;
 //DisplayVector(listIntegers);
 //cout << "After ereasing element" << *iValue2 << "':" << endl;
 //listIntegers.erase(iValue2);
 //DisplayVector(listIntegers);
 //listIntegers.erase(listIntegers.begin(), listIntegers.end());
 //cout << "Number of elements after erasing range:";
 //cout << listIntegers.size() << endl;
 list  listIntegers;
 listIntegers.push_back(4);
 listIntegers.push_back(3);
 listIntegers.push_back(2);
 listIntegers.push_back(1);
 listIntegers.push_back(0);
 listIntegers.push_back(5);
 cout << "Intial contents of the list:" << endl;
 DisplayVector(listIntegers);
 listIntegers.reverse();
 cout << "Content of the list after using reverse():" << endl;
 DisplayVector(listIntegers);
 listIntegers.sort();
 cout << "order of element after sort():" << endl;
 DisplayVector(listIntegers);
 system("pause");
 return 0;
}

你可能感兴趣的:(C++)