public void appendToTail(int d) { Node end = new Node(d); Node n = this; while (n.next != null) { n = n.next; } n.next = end; }
public int? pop() { if (top != null) { int item = top.data; if (top.data == values.First()) { // find a new minimum... but how to do this in O(1) time? values.RemoveAt(0); } top = top.next; return item; } return null; }
public void push(int d) { Node item = new Node(d); if (top != null) { item.next = top; top = item; } top = item; values.Add(d); values.Sort(); Console.WriteLine("values: "); foreach(int x in values) { Console.WriteLine("- " + x); } }