public void Push(int value)
        {
            DinElement el = new DinElement(value);

            el.Adress = top;
            top       = el;
        }
 public int Pop()
 {
     if (isEmpty())
     {
         throw new Exception("Стек пустой!");
     }
     else
     {
         int temp = top.Value;
         top = top.Adress;
         return(temp);
     }
 }
        public override string ToString()
        {
            string     s    = "";
            DinElement temp = top;

            while (temp != null)
            {
                s   += temp.Value + " ";
                temp = temp.Adress;
            }
            return(s);
            //top.Value + " " + top.Adress.Value + " " + top.Adress.Adress.Value;
        }
예제 #4
0
        static void Main(string[] args)
        {
            DinElement a = new DinElement(3);

            Console.WriteLine(a);

            DinElement b = new DinElement();

            b.Value = 45;
            Console.WriteLine(b);

            DinStack st = new DinStack();

            st.Push(3);
            st.Push(5);
            st.Push(1);

            Console.WriteLine(st);

            Console.WriteLine(st.Peek());
        }
 public DinElement()
 {
     val = 0;
     adr = null;
 }
 public DinElement(int a)
 {
     val = a;
     adr = null;
 }