import javax.swing.*;
class nodeStack
{
Object info;
nodeStack link;
static nodeStack head, next, tail, last;
public nodeStack(Object i, nodeStack l) //CONSTRUCTOR
{ info = i;
link = l; }
//add node
static void doAdd()
{
int i = Integer.parseInt(JOptionPane.showInputDialog(“Add Node\nEnter a number”));
if(head == null)
{
head = new nodeStack(i,null);
tail = head;
}
else
{
next = new nodeStack(i,null);
tail.link = next;
tail=next;
}
}
//display
static void doDisplay()
{
String output=””;
last = tail;
if (head != null)
{
if (head == last)
output += head.info + ” “;
else
{
while(head != last)
{
next = head;
while(next.link != last)
{
next = next.link;
}
output += last.info + ” “;
last = next;
}
output += head.info + ” “;
}
JOptionPane.showMessageDialog(null, “Array List Content\n” + output);
}
else
JOptionPane.showMessageDialog(null, “List is empty”);
}
//delete
static void doDelete()
{
if (head != null)
{
if (head == tail)
head = null;
else
{
next = head;
while(next.link != tail)
{
next = next.link;
}
next.link = null;
tail = null;
tail = next;
}
JOptionPane.showMessageDialog(null, “Tail node deleted”);
}
else
JOptionPane.showMessageDialog(null, “List is empty”);
}
public static void main(String[] args)
{
String menu = “MAIN MENU\n” +
“[1] Add node\n”+
“[2] Display list\n” +
“[3] Delete node\n” +
“[4] Exit”;
int choice=0;
do
{
String str = JOptionPane.showInputDialog(menu);
if(str.equals(“”))
JOptionPane.showMessageDialog(null, “enter a number”);
else
{
choice = Integer.parseInt(str);
if (choice == 1)
doAdd();
else if (choice == 2)
doDisplay();
else if (choice == 3)
doDelete();
else if (choice == 4)
JOptionPane.showMessageDialog(null, “Programmer: eugene”);
}
} while(choice != 4);
} }