Question: Read over the code carefully, noting what each part does. Implement each place that says fill in here. Get your program compiled and running. Run

  • Read over the code carefully, noting what each part does.
  • Implement each place that says fill in here.
  • Get your program compiled and running.
  • Run your code and test it! The expected output is at the bottom.
#include  using namespace std; template  struct ListNode { ListNode(T const &x, ListNode *_next=nullptr) : data(x), next(_next) {} ~ListNode() { delete next; } T data; ListNode *next; }; template  struct ListIterator { ListIterator(ListNode *_current=nullptr) { /* fill in here */ } ListNode *current; ListIterator &operator++() { /* fill in here */ return *this; } T const &operator*() const { return /* fill in here */ } bool operator!=(ListIterator const &x) const { return /* fill in here */ } }; template  struct LinkedList { LinkedList() : front(nullptr), back(nullptr) {} ~LinkedList() { delete front; } ListNode *front, *back; void add_back(T const &x) { /* fill in here -- be careful on the first "add" to update both "front" and "back" */ } void add_front(T const &x) { /* fill in here -- be careful on the first "add" to update both "front" and "back" */ } ListIterator begin() { return /* fill in here */ } ListIterator end() { return /* fill in here */ } }; int main() { LinkedList ll; // add a bunch of stuff for (int i = 0; i < 5; ++i) { ll.add_front(i * 3); ll.add_back(i * 7 + 1); } // print everything using the iterator interface for (ListIterator i = ll.begin(); i != ll.end(); ++i) { cout << *i << " "; } cout << endl; // expected output: "12 9 6 3 0 1 8 15 22 29 " return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!