• Source
    1. #include <iostream>
    2. #include <bits/stdc++.h>
    3. using namespace std;
    4.  
    5. int main() {
    6. // your code goes here
    7. list <int> list1;
    8.  
    9. list1.push_back(10);
    10. list1.push_back(40);
    11.  
    12. list1.push_front(60);
    13. list1.push_front(70);
    14.  
    15. cout << "we have just created a list travesing using C++11 range based for loop" << endl;
    16. for( int i:list1 )
    17. cout << i << " ";
    18. cout <<endl;
    19.  
    20.  
    21. list1.pop_back();
    22. cout << "list after doing pop back" << endl;
    23. for( int i:list1 )
    24. cout << i << " ";
    25. cout << endl;
    26.  
    27. // printing using iterator there are 2 sytels for iterator.
    28. cout << "travesing list using auto iterator" << endl;
    29. for( auto itr = list1.begin() ; itr != list1.end(); itr++ )
    30. {
    31. cout << *itr << " ";
    32. }
    33. cout << endl;
    34.  
    35. // printing using std:: iterator.
    36. cout << "travesing list using std :: iterator" << endl;
    37. list<int> :: iterator itr;
    38. for( itr = list1.begin() ; itr != list1.end(); itr++ )
    39. {
    40. cout << *itr << " ";
    41. }
    42. cout << endl;
    43.  
    44.  
    45.  
    46. return 0;
    47. }