Exemplo n.º 1
0
 public void appendToTail(int d)
 {
     Node end = new Node(d);
     Node n = this;
     while (n.next != null)
     {
         n = n.next;
     }
     n.next = end;
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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);
            }
        }