fork download
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. void printList(list<int> list);
  7. void printList(list< list<int> > list);
  8. void printListPointers(list<int> list);
  9. void printListPointers(list< list<int> > list);
  10.  
  11. class List {
  12. public:
  13. List(int, int);
  14. list< list<int> > root;
  15. };
  16.  
  17. List::List(int a, int b) {
  18. list<int> l;
  19. l.push_back(a);
  20. l.push_back(b);
  21. root.push_back(l);
  22. cout << "constructor, values: root "; printList(root); cout << endl;
  23. cout << "constructor, values: first node in root "; printList(*(root.begin())); cout << endl;
  24. cout << "constructor, pointers: root "; printListPointers(root); cout << endl;
  25. cout << "constructor, pointers: first node in root "; printListPointers(*(root.begin())); cout << endl;
  26. }
  27.  
  28. int main() {
  29. List foo = List(2, 3);
  30. cout << "main, values: root "; printList(foo.root); cout << endl;
  31. cout << "main, values: first node in root "; printList(*(foo.root.begin())); cout << endl;
  32. cout << "main, pointers: root "; printListPointers(foo.root); cout << endl;
  33. cout << "main, pointers: first node in root "; printListPointers(*(foo.root.begin())); cout << endl;
  34.  
  35. return 0;
  36. }
  37.  
  38. void printList(list<int> l) {
  39. cout << "{";
  40. for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
  41. cout << *it << ", ";
  42. }
  43. cout << "}";
  44. }
  45.  
  46. void printList(list< list<int> > l) {
  47. cout << "{";
  48. for (list< list<int> >::iterator it = l.begin(); it != l.end(); it++) {
  49. printList(*it);
  50. }
  51. cout << "}";
  52. }
  53.  
  54. void printListPointers(list<int> l) {
  55. cout << "{";
  56. for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
  57. cout << &*it << ", ";
  58. }
  59. cout << "}";
  60. }
  61.  
  62. void printListPointers(list< list<int> > l) {
  63. cout << "{";
  64. for (list< list<int> >::iterator it = l.begin(); it != l.end(); it++) {
  65. cout << &*it << ", ";
  66. }
  67. cout << "}";
  68. }
Success #stdin #stdout 0.01s 2820KB
stdin
Standard input is empty
stdout
constructor, values: root {{2, 3, }}
constructor, values: first node in root {2, 3, }
constructor, pointers: root {0x96ff068, }
constructor, pointers: first node in root {0x96ff090, 0x96ff080, }
main, values: root {{2, 3, }}
main, values: first node in root {2, 3, }
main, pointers: root {0x96ff068, }
main, pointers: first node in root {0x96ff010, 0x96ff020, }