Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.EmptyStackException; / / import java.util.Stack; public class A 3 Stack implements Stack { private A 3 bNode head; / / Do NOT add any
import java.util.EmptyStackException;
import java.util.Stack;
public class AStack implements Stack
private AbNode head;
Do NOT add any other fields to this class.
You should be able to implement the Stack
interface with just a head field.
public AStack
head null;
public void pushT value
AbNode newNode new AbNodevalue;
newNode.next head;
head newNode;
public T pop
AbNode temp head;
head head.next;
return temp.getData;
public void popAll
head null;
public void makeEmpty
head null;
public boolean isEmpty
return head null;
public T peek
return head.getData;
public int size
int count ;
AbNode curr head;
while curr null
count;
curr curr.next;
return count;
Implemented for you for debugging purposes
public String toString
String result ;
String separator ;
AbNode cur head;
while cur null
result separator cur.getDatatoString;
separator ;
cur cur.next;
result ;
return result;
Is recieving this error: error: type Stack does not take parameters
public class AStack implements Stack
error
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