Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

Describe the components of a formal report.

Answered: 1 week ago