public int Pop() { if (head == null) { throw new Exception("Stack is empty"); } var node = head; head = head.next; return(node.data); }
public void Push(int val) { Linkedlist <int> node = null; if (head == null) { head = new Linkedlist <int>(); node = head; head.data = val; } else { node = new Linkedlist <int>(); node.data = val; node.next = head; head = node; } }