public static void NotMain(String[] args) { Stack s = new Stack(); s.Push(5); s.Push(1); s.Push(2); s.Push(3); s.Push(4); Console.WriteLine(s); s = Sort(s); Console.WriteLine(s); Console.Read(); }
public static Stack Sort(Stack s) { Stack r = new Stack(); while (!s.IsEmpty()) { Node temp = s.Pop(); while(!r.IsEmpty() && r.Peek().data > temp.data) { s.Push(r.Pop()); } r.Push(temp); } return r; }
public void Push(int n) { Node node = new Node(n); Stack last; if (stacks.Count == 0) { last = new Stack(); stacks.Add(last); } else last = stacks.ElementAt(stacks.Count - 1); if (last.GetSize() == stackLimit) { last = new Stack(); stacks.Add(last); } last.Push(n); //PrintStacks(); }
public Node TakeOne(Stack s) { //Assume s has as least one element. Node bottom = s.top; //If there is only one element. if (bottom.next == null) { s.top = null; return bottom; } while (bottom.next.next != null) { bottom = bottom.next; } Node temp = bottom.next; bottom.next = null; return temp; }
public MyQueue() { inStack = new Stack(); outStack = new Stack(); }
public MinStack() { mins = new Stack(); }