CJCoding With Joseph
15free / daySign inCreate account

Create a class IntList, a singly linked list of ints, with: 1. A private nested struct Node { int value; Node* next; }; 2. A private Node* head (initially nullptr) and Node* tail, so push_back is O(1). 3. IntList() starts empty; ~IntList() deletes EVERY node. 4. void push_back(int value): appends a node at the end. 5. A public nested class Iterator holding a Node* cur, with exactly: Iterator(Node* p); int operator*() const returning cur->value; Iterator& operator++() that moves cur to cur->next and returns *this; bool operator!=(const Iterator& other) const, true when the cur pointers differ. 6. Iterator begin() const on head, and Iterator end() const on nullptr.

Your class prints nothing — the hidden test does. Test 1 pushes 10, 20, 30, prints each value followed by a space using for (int x : lst), then a newline, then Sum: 60 (see Expected Output).

Test 2 pushes 7 and 8, walks the list with an explicit IntList::Iterator loop, and prints 7 8 on one line then Count: 2 on the next.

Do NOT write a main function.

Expected output

10 20 30
Sum: 60
7 8
Count: 2

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
STL ContainersIterators
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.