示例#1
0
        public void print()
        {
            LinkedStack <T> _this = this;

            Console.Write("Stack: < ");
            while (_this != null)
            {
                Console.Write(_this.data + " ");
                _this = _this.link;
            }
            Console.WriteLine(">");
        }
示例#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;
            }
        }
示例#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;
        }
示例#4
0
 public LinkedStack(T data)
 {
     this.data = data;
     this.link = null;
 }
示例#5
0
 public LinkedStack()
 {
     this.data = default(T);
     this.link = null;
 }