import java.util.Stack;
public class Main {
public static void main(String[] args) {
LinkedStack<String> stack=new LinkedStack<>();
stack.push("1");
stack.push("1");
stack.push("1");
stack.push("1");
stack.push("1");
stack.push("1");
stack.push("1");
stack.push("1");
System.out.println(stack.pop());
}
}
class LinkedStack<E>{
Node<E> headNode;
public static class Node<E>{
E item;
Node<E> next;
Node(E element,Node<E> next){
this.item=element;
this.next=next;
}
}
LinkedStack(){
headNode= new Node<E>(null,null);
}
public boolean empty(){
return headNode.next==null;
}
public E peek(){
if(empty()){
return null;
}
return headNode.next.item;
}
public E pop(){
if(empty()){
return null;
}
E e=headNode.next.item;
headNode.next=headNode.next.next;
return e;
}
public E push(E item){
Node<E> sNode=new Node<E>(item,headNode.next);
headNode.next=sNode;
return item;
}
}