Example #1
0
        static void Main(string[] args)
        {
            Stack stack = new Stack();
           	int whatDo = -1;
	        while (whatDo != 0)
	        {
		        Console.WriteLine("0 - exit"); 
			    Console.WriteLine("1 - push"); 
			    Console.WriteLine("2 - pop"); 
			    whatDo = Convert.ToInt32(Console.ReadLine());
		        if (whatDo == 1)
		        {
			        int newNum = 0;
			        Console.WriteLine("Enter number for add - ");
			        newNum = Convert.ToInt32(Console.ReadLine());
			        stack.Push(newNum);
		        }
		        if (whatDo == 2)
		        {
                    int value = stack.Pop();
                    if (value == -1)
                        Console.WriteLine("Stack is empty");
                    else
                        Console.WriteLine("delete element - {0}", value);
			    }
		        stack.Print();
		    }
        }
Example #2
0
 public void Initialize()
 {
     stack = new Stack<int>();
 }
Example #3
0
 public Calculator(Stack newStack)
 {
     stack = newStack;
 }