Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define a class DoublyLinkedBag that implements the ADT bag by using a doubly linked chain, as shown in Figure 4-9. Use the class of node
Define a class DoublyLinkedBag that implements the ADT bag by using a doubly linked chain, as shown in Figure 4-9. Use the class of node .Demonstrate your double linked list implementation in a main function. Tips: Unlike the previous assignment (with arrays) we are not using integers as our data - but the ADT bag, which uses templates. It would be best to implement the ADT linked based implementation of bag first. This majority of this code is done for you in the textbook. Then simply modify the LinkedBag code to handle a double linked list.
- Inputs
- Modification of the Node class: Constructor/descructor for the new node (w/ a next and prev pointers)
- Modification of the Node class: addition of setPrev and getPrev Functions
- Processing
- Modification of the LinkedBag class: constructors and destructors
- Modification of the LinkedBag class: add and remove
- Output
- main.cpp demonstrates the initialization and destruction of a double linked list.
- main.cpp demonstrates an addition and removal from the double linked list.
- In a doubly linked chain, each node can point to the previous node as well as to the next node. Figure 4-10 shows a doubly linked chain and its head pointer. That's all it says. Moreover, we need to define our own class. Thanks.
- The only thing that I can think of is,
- template
- class IDoubleNode
- {Private:
- T data ;
- public:
- IDoubleNode* next;
- IDoubleNode* previous;
- IDoubleNode* (T data);
- T getData();
- string toString();
- ~IDoubleNode();
- };
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started