Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

**Use the Stack interface to implement the LinkedStack.java class.

Stack.java

public interface Stack<E> {
/**
* Push an element onto the stack.
*
* @param element, a value to be pushed on the stack
*/
public void push(E element);

/**
* Pop the top element off the stack.
*/
public E pop();

/**
* Return the top element on the stack.
*/
public E top();

/**
* Return True if the stack contains no elements.
*
* @return true if there are no elements in the stack
*/
public boolean isEmpty();
}

***In LinkedStack.java, change only The methods with empty bodies Do not use a sentinel node. In this implementation you use an inner class That is, a class that is declared inside of another class. The Node class isn't needed by any other class, so it is declared as a private class inside the LinkedStack class. The Node class has two fields: element and next. Things to note in the class LinkedStack: The EmptyStackExceptionis being used, same as in the ArrayStack. The class StringJoineris imported for use in the toString()

LinkedStack.java

import java.util.EmptyStackException;
import java.util.StringJoiner;
public class LinkedStack<E> implements Stack<E> {
private class Node {
public E element;
public Node next;

public Node(E element) {
this(element, null);
}

public Node(E element, Node next) {
this.element = element;
this.next = next;
}
}

private Node top;
/**
* Constructor for objects of class LinkedStack
*/
public LinkedStack() {
}
@Override
public void push(E element) {
// Complete this method
}

@Override
public E pop() {
// Complete this method
}

@Override
public E top() {
// Complete this method
}

@Override
public boolean isEmpty() {
// Complete this method
}

@Override
public int size() {
// Complete this method
}

 


@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", "[", "]");
for (Node current = top; current != null; current = current.next) {
joiner.add(current.element.toString());
}
return joiner.toString();
}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education