Implement the stack using a linked list. Use the followingclass definition for t
ID: 3611951 • Letter: I
Question
Implement the stack using a linked list. Use the followingclass definition for the stack and use the given main method totest your implementation.
public class Stack
{
private class node
{
intdata;
node next;
}
private node myTop;//pointer to the top ofthe stack
public Stack()
{//Create an empty stack }
public boolean empty()
{// return true if stack is empty,otherwise return false}
public void push(int value)
{//add to the top of the stack }
public void display()
{//display data stored in stack fromtop to bottom}
public int top()
{//return the top of the stack}
public void pop()
{//remove the value at the top of thestack}
}
public static void main(String[] args)
{
Stack S = new Stack();
// insert each value 1 through 5 onto thestack
for(int x = 1; x<=5; x++)
S.push(x);
//Display the content of the stack to thescreen
S.display();
//Remove and display each value on thestack
while (!S.empty())
{ int x;
x = S.top();
System.out.println();
System.out.println(“Popping… “ + x);
S.pop();
S.display();
}
if (S.empty())
System.out.println(“Stack isempty.”);
}