Question: Consider the Doubly Linked List-based implementation of the Stack ADT, the code for which is given to you and also discussed in class. According to

 Consider the Doubly Linked List-based implementation of the Stack ADT, the

Consider the Doubly Linked List-based implementation of the Stack ADT, the code for which is given to you and also discussed in class. According to this code, the latest data to be pashed to the Stack is inserted at the tail/end of the list and the earliest pushed data is in the bottom of the stack. This implies that (as peT the code piven to you) the node next to the bead node has its data at the bottom of the stack and the node peevious to the tail node has its dala at the top of the stack. The Iierativerin function given in the code prines the contents of the Stack from the head node to the tail node The follkowing figure illustrates a Stack with elements pushed in this order: 10,9,5 and a call to the terativePriat) function will also prist the elements in this oeder, Note that the abbeeviations PNP and NNP in the figure refer to PrevNodePtr and NextNodePtr respectively 0 10 300 Tail Node Head Node 1004 200 500 400 Top of the Stack headPtr 100 tailPtr 400 Bottiom of the Stack Stack In this question, you are required to reverse the links of the Doubly Linked List-based implementation of the Stack such that the tailPtr points to the head node (and bence the head node has to be ow appeopriately referred to as the tail mode) and the headPr points to the tail node (and hence the tail node has to be now appropriately referred to as the head node), as well as the values for the prevNodePir and nextNodePtr pointers for every node (inckading the head node and tail node) swapped between themelves. With all these link seversals, the node nest to the head node has its data at the top of the stack and the node previous to the tail node has its duta at the bottom of the stack. A call lo the IicrativePri functicn (that is designed to print the Stack from the head node to the tasl node) will now print the coatents o the Stack froen the top to the botom (as the next node of the head node has its data now at the top of the stack) as: 5,9. 10. The Stack of the esampk shown above will look like thc fipure below after the link reversals, Note that the values for the PNP and NNP are swapped as highlighied (cg. for the node with data 10, the PNP and NNP were respoctively 0 and 500 before the liek reversals, and are 500 and 0 respectively, after the link reversals) Tail Node @100 2 200 500 300 Head Node 400 Top of the Stack tailPtr 100 headPtr 400 Bottiom of the Stack You need te include the following as part of your answer to this question: (i) the entire code for the Doubly linked list-based implementation of the Stack class, including the revcrseStackfunction Gii) snapshot of the esecution of the code for list size of 10 and maximums value for each element heing

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!