fork download
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. void printList(list<int>myList){
  6. for(list<int>::iterator it = myList.begin(); it != myList.end(); it++){
  7. cout << *it << " ";
  8. }
  9. cout << endl;
  10. }
  11. bool Numb( int x ){
  12. return( x % 10 ) > 4;
  13. }
  14. int main() {
  15. list<int> myList;
  16. int myInt;
  17. for( int i = 0; i < 5; i++){
  18. cin >> myInt;
  19. myList.push_back(myInt);
  20. }
  21. printList(myList);
  22. myList.push_front(23);
  23. myList.push_front(2);
  24. myList.push_front(41);
  25. printList(myList);
  26.  
  27. myList.sort();
  28. printList(myList);
  29.  
  30. myList.pop_front();
  31. printList(myList);
  32.  
  33. cout << myList.front() << endl;
  34.  
  35. myList.pop_back();
  36. printList(myList);
  37.  
  38. cout << myList.back() << endl;
  39.  
  40. cout << myList.size() << endl;
  41.  
  42. myList.remove(23);
  43. printList(myList);
  44.  
  45. myList.remove_if(Numb);
  46. printList(myList);
  47. return 0;
  48. }
Success #stdin #stdout 0s 5284KB
stdin
3 6 8 90 7
stdout
3 6 8 90 7 
41 2 23 3 6 8 90 7 
2 3 6 7 8 23 41 90 
3 6 7 8 23 41 90 
3
3 6 7 8 23 41 
41
6
3 6 7 8 41 
3 41