Question
I need a little help here. I do not know why this error is happening. I am pretty sure I extended the class right but
I need a little help here. I do not know why this error is happening. I am pretty sure I extended the class right but any help is greatly appreciated.
Here is the code that I have...... I was not given the LLNode class. If you have a different way to return the size of the linked stack that would be appreciated as well.
package ch02.stacks; import support.LLNode;
public class LinkedStack implements StackInterface { public LLNode top; // reference to the top of this stack public LinkedStack() { top = null; } public void push(T element) // Places element at the top of this stack. { LLNode newNode = new LLNode(element); newNode.setLink(top); top = newNode; }
public void pop() // Throws StackUnderflowException if this stack is empty, // otherwise removes top element from this stack. { if (isEmpty()) throw new StackUnderflowException("Pop attempted on an empty stack."); else top = top.getLink(); }
public T top() // Throws StackUnderflowException if this stack is empty, // otherwise returns top element of this stack. { if (isEmpty()) throw new StackUnderflowException("Top attempted on an empty stack."); else return top.getInfo(); }
public boolean isEmpty() // Returns true if this stack is empty, otherwise returns false. { return (top == null); }
public boolean isFull() // Returns false - a linked stack is never full { return false; }
----------------------------------------------------------------------------------------------------------------
import ch02.stacks.*;
public class LinkedExtended extends LinkedStack { // returns the size of stack public int size() { int size = 0; // counting the number of nodes for (LLNode temp = top; temp != null; temp = temp.getLink()) { size++; } return size; } // method to pop top count values public void popSome(int count) { // looping for count times for (int i = 0; i stack size, underflow if (top == null) { throw new StackUnderflowException("Not enough values to remove!"); } // removing top top = top.getLink(); } } // method to swap two values at top public boolean swapStart() { if (top == null || top.getLink() == null) { // not enough values return false; } // swapping elements at top and top.getLink() T temp = top.getInfo(); top.setInfo(top.getLink().getInfo()); top.getLink().setInfo(temp); return true; } // method to pop and return the top value from the stack public T poptop() { if (top == null) { // empty stack throw new StackUnderflowException("Stack is empty!"); } // storing top element T data = top.getInfo(); // removing top top = top.getLink(); // returning removed data return data; } }
LinkedExtended.java:10: error: cannot find symbol for (LLNodeStep 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