package work2;
public class link1 {
public long dData;
public link1 next;
public link1(long dd) {
this.dData=dd;
}
public void display() {
System.out.println(dData+" ");
}
public static void main(String[] args) {
linkstack theStack = new linkstack();
theStack.push(34);
theStack.push(545);
theStack.displayStack();
}
}
class Linklist1{
private link1 first;
public Linklist1() {
first=null;
}
public boolean isEmpty() {
return (first==null);
}
public void insertFirst(long dd) {
link1 newLink = new link1(dd);
newLink.next = first;
first = newLink;
}
public long deleteFirst() {
link1 temp = first;
first = first.next;
return temp.dData;
}
public void displaylist() {
link1 current = first;
while(current != null) {
current.display();
current=current.next;
}
System.out.println(" ");
}
}
class linkstack{
private Linklist1 thelist;
public linkstack() {
thelist = new Linklist1();
}
public void push(long dd) {
thelist.insertFirst(dd);
}
public long pop() {
return thelist.deleteFirst();
}
public void displayStack() {
System.out.println("Stack (top-->bottom)");
thelist.displaylist();
}
}