Question
provide code fragments that implement two methods. You do not need to provide anything other than those two methods. Imagine using a doubly linked list
provide code fragments that implement two methods. You do not need to provide anything other than those two methods.
Imagine using a doubly linked list to implement the stack ADT for values of a generic type. Skeleton code is provided below. Implement the push and pop methods. Instead of using the methods of the List ADT, manipulate the nodes directly. Make sure to handle any major error conditions by throwing a new RuntimeException. This doubly linked list uses sentinel nodes and you can assume that beginMarker and endMarker have already been initialized properly.
class LinkedListStack {
private static class Node { public Node(E d, Node p, Node n) {
data = d; prev = p; next = n; }
Node prev; Node next; E data;
}
Node beginMarker;
Node endMarker;
public void push(E x) { /* put the code for this in the file that you will upload */ }
public E pop() { /* put the code for this in the file that you will upload */ } }
Step by Step Solution
3.38 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
CODE class LinkedListStack private static class Node E data Node prev next public NodeE data Node p...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