Question
How come the top artist is the bottom object. Shouldnt the top artist be Vincent van gogh ? linkedStack class: public class LinkedStack implements StackInterface
How come the top artist is the bottom object. Shouldnt the top artist be "Vincent van gogh" ? linkedStack class:
public class LinkedStack
private LinearNode
private int count;
private T[] stack;
public LinkedStack() {
top = null;
count = 0;
}
public LinkedStack(T element) {
top = new LinearNode
count = 1;
}
public void push(T element) {
// creating a new node, positioning before current top, setting as new
// top and updating count
LinearNode
node.setNext(top);
top = node;
count++;
}
public T pop() throws StackException {
if (count == 0)
throw new StackException();
T temp = top.getElement();
top = top.getNext();
count--;
return temp;
}
public T peek() throws StackException {
if (count == 0)
throw new StackException();
//returning top element
return top.getElement();
}
@Override
public int size() {
return count;
}
@Override
public boolean isEmpty() {
return count == 0;
}
public String toString() {
// initializing an empty String variable
String str = "";
// taking reference to head
LinearNode
// looping until curr is null
while (curr != null) {
// fetching element and appending to str
str += curr.getElement();
// if there are more node(s) appending a newline to str
if (curr.getNext() != null) {
str += " ";
}
// advancing to next node
curr = curr.getNext();
}
// returning str
return str;
}
package Class; HNM non 5
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