Answered step by step
Verified Expert Solution
Link Copied!

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.image text in transcribed
  • 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();
  • };
FIGURE 4-9 (a) A linked chain and its (b) shallow copy; (c) deep copy 4 "ab" "cd""ef""gh" i temCount headPtr 4 Copy of i temCount Copy of headPtr Shallow copy 4 ab" "gh" Copy of Copy of Copy of the linked chain i temCount headPtr Deep copy FIGURE 4-9 (a) A linked chain and its (b) shallow copy; (c) deep copy 4 "ab" "cd""ef""gh" i temCount headPtr 4 Copy of i temCount Copy of headPtr Shallow copy 4 ab" "gh" Copy of Copy of Copy of the linked chain i temCount headPtr Deep copy

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

More Books

Students also viewed these Databases questions