Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Implement an inorder as a doubly linked list. Your implementation should have the following methods: first(): returns the first element in the list

 

1. Implement an inorder as a doubly linked list. Your implementation should have the following methods: first(): returns the first element in the list without changing the contents of the list. Should output an error message if the list is empty. last(): returns the last element in the list without changing the contents of the list. Should output an error message if the list is empty. insert(element): inserts an element in its correct place in the list. If the element already exists do nothing. remove(element): removes the element from the list. Returns true if the element was in the list and false otherwise, print(): prints the contents of the list. reverse: reverses the contents of the list The default should be for inserting elements in an ascending order, but a call to the reverse function should reverse the contents of the list as well as reverse the order in which elements are to be inserted so if it was ascending it should be descending and vice versa. Assuming you declared a L as an inOrderList, the following code should result in the shown output: L.insert (5); L.insert (6); L.insert (1); L.insert (2); L. print(); Output: 1, 2, 5, 6 L.reverse(); L. print(); Output: 6, 5, 2, 1 L. insert (7); L.insert (3); L.print() Output: 7, 6, 5, 3, 2, 1 L. reverse(); L. insert (4); L. insert (9); L.print() Output: 1, 2,3, 4, 5, 6, 7, 9 L.remove (2); L. remove (9); L.print() Output: 1, 3, 4, 5, 6, 7 cout < < L. first(); Output: 1

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

Introduction To Java Programming And Data Structures Comprehensive Version

Authors: Y. Daniel Liang

12th Edition

0136520235, 978-0136520238

More Books

Students also viewed these Programming questions

Question

Describe what this statement does: print user name = + userName

Answered: 1 week ago

Question

Do you get worried when group confl ict appears?

Answered: 1 week ago

Question

What incidents in this session bothered you the most?

Answered: 1 week ago