コード例 #1
0
        public void Push(int value)
        {
            DinElement el = new DinElement(value);

            el.Adress = top;
            top       = el;
        }
コード例 #2
0
 public int Pop()
 {
     if (isEmpty())
     {
         throw new Exception("Стек пустой!");
     }
     else
     {
         int temp = top.Value;
         top = top.Adress;
         return(temp);
     }
 }
コード例 #3
0
        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());
        }
コード例 #5
0
 public DinElement()
 {
     val = 0;
     adr = null;
 }
コード例 #6
0
 public DinElement(int a)
 {
     val = a;
     adr = null;
 }