Esempio n. 1
0
        public void print()
        {
            LinkedStack <T> _this = this;

            Console.Write("Stack: < ");
            while (_this != null)
            {
                Console.Write(_this.data + " ");
                _this = _this.link;
            }
            Console.WriteLine(">");
        }
Esempio n. 2
0
        public void push(T data)
        {
            LinkedStack <T> node = new LinkedStack <T>(data);

            if (this.link == null)
            {
                this.link = node;
            }
            else
            {
                LinkedStack <T> temp = this;
                while (temp.link != null)
                {
                    temp = temp.link;
                }
                temp.link = node;
            }
        }
Esempio n. 3
0
        public void pop()
        {
            if (this.link == null)
            {
                Console.WriteLine("Sorry. You can't empty the stack.");
                return;
            }

            if (this.link.link == null)
            {
                this.link = null;
                return;
            }

            LinkedStack <T> temp = this.link;

            while (temp.link.link != null)
            {
                temp = temp.link;
            }
            temp.link = null;
        }
Esempio n. 4
0
 public LinkedStack(T data)
 {
     this.data = data;
     this.link = null;
 }
Esempio n. 5
0
 public LinkedStack()
 {
     this.data = default(T);
     this.link = null;
 }