Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Doubly Linked List. Class should be called DoublyLinkedList. The Node structure , with fields prev, item, and next. You will want to add a pointer

Doubly Linked List. Class should be called DoublyLinkedList. The Node structure , with fields prev, item, and next. You will want to add a pointer to the last node in the list as discussed in class. All existing methods must be suitably modified. Copy Constructor Add a new method void reverse() which reverses the list. it must reverse the list simply by modifying pointers. Add a new method called vector toVector(bool reverse) that returns a vector (the vector class is in the C++ standard library!) populated with the items in the list, in forward order, unless reverse is true, in which case the vector should be populated with the list items in reverse order (the list itself does not change). Remember you can easily go through a doubly linked list in either order, and you have a tail pointer so you now where the last node The Main Program First Create a sub-routine void print(const char* msg, const vector& vec) that will print the msg passed, followed by the contents of the vector. For example, if the msg is Hello, and vector contains XX, YY, ZZ, the print function would print: Hello [ XX YY ZZ ] . Create a DoublyLinkedList of strings (typedef string E), using the add method, that contains this data: AA, BB, CC, DD, EE 2. Call toVector(false) and print the resulting vector by calling the print method with msg S2. The items should print in forward order .Call toVector(true) and print the resulting vector by calling the print method with msg S3. The items should print in reverse order . Call add(0, XX); add(3, YY); add(7, ZZ) . Call toVector(false) and print the resulting vector by calling the print method with msg S5. The items should print in forward order 6. Call toVector(true) and print the resulting vector by calling the print method with msg S6. The items should print in reverse order . Create a new list as a copy of the existing list using the copy constructor: DoublyLinkedList list2(list1) or DoubleLinkedList list2 = list1; Using this new list (list2): . Call toVector(false) and print the resulting vector by calling the print method with msg S8. The items should print in forward order . Call remove(0); remove(2); remove(5); . Call toVector(false) and print the resulting vector by calling the print method with msg S10. The items should print in forward order . Call reverse();Call toVector(false) and print the resulting vector by calling the print method with msg . The items should print in the new forward order . Call toVector(true) and print the resulting vector by calling the print method with msg . The items should print in the new reverse order

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

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions