Exemplo n.º 1
0
        static void Main()
        {
            LinkedListStack stack = new LinkedListStack();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);
            stack.Push(5);

            Console.WriteLine("Stack Pop: {0}", stack.Pop());
            Console.WriteLine("Stack Pop: {0}", stack.Pop());
            Console.WriteLine("Stack Pop: {0}", stack.Pop());
            Console.WriteLine("Stack Peek: {0}", stack.Peek());
            Console.WriteLine("Stack Pop: {0}", stack.Pop());

            stack.Push(6);
            Console.WriteLine("Stack Pop: {0}", stack.Pop());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        /// <summary>
        /// <param name="N">Number of disks</param>
        /// Constructor which initializes the stack and the disk array
        /// </summary>
        public TowersOfHanoi(int N)
        {
            stacks = new LinkedListStack[3];

            disks = new int[N];

            for (int i = 0; i < 3; i++)
            {
                stacks[i] = new LinkedListStack();
            }

            // Initializing disk array and first stack
            for (int i = 0; i < N; i++)
            {
                disks[i] = i;
                stacks[0].Push(N - i);
            }

            // Initializing length of stacks
            stackLength    = new int[3];
            stackLength[0] = N;
            stackLength[1] = 0;
            stackLength[2] = 0;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor initializing the main and temp stack
 /// </summary>
 public SortStack()
 {
     s1 = new LinkedListStack();
     s2 = new LinkedListStack();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor initializing the two stacks
 /// </summary>
 public MyQueue()
 {
     s1 = new LinkedListStack();
     s2 = new LinkedListStack();
 }