コード例 #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;
 }