using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Stacks { class Stack { private Node head; public Stack() { head = null; } public bool isEmpty() { return head == null; } public void push(T x) { head = new Node(x, head); } public T pop() { if (isEmpty()) return default(T); T val = head.getValue(); head = head.getNext(); return val; } public T top() { if (isEmpty()) return default(T); return head.getValue(); } public override string ToString() { string baseStr = "["; while (!isEmpty()) { if (baseStr.Length > 1) baseStr += ", "; baseStr += pop().ToString(); } baseStr += "]"; return baseStr; } } }