Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribed

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 (LLNode temp - top; temp != null; temp = temp.getLink() symbol: class LLNode location: class LinkedExtended where T is a type-variable: T extends Object declared in class LinkedExtended

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

Use integration by parts to show that () = ( 1) ( 1) for > 1.

Answered: 1 week ago

Question

7. Where Do We Begin?

Answered: 1 week ago