예제 #1
0
        //returns the most recently added string and removes it from the stack
        public String Pop()
        {
            String popString = Peek();

            //if it only stringnode
            if (head == tail)
            {
                head = null;
                tail = null;
            }
            else
            {
                StringNode nodeWalker = head;

                while (nodeWalker.Next != tail)
                {
                    nodeWalker = nodeWalker.Next;
                }

                //if next stringnode is tail
                if (nodeWalker.Next == tail)
                {
                    tail            = nodeWalker;
                    nodeWalker.Next = null;
                }
            }

            return(popString);
        }
예제 #2
0
        //returns the most recently added string and removes it from the stack
        public String Pop()
        {
            String popString = Peek();

            //if it only stringnode
            if (head == tail)
            {
                head = null;
                tail = null;
            }
            else
            {
                StringNode nodeWalker = head;

                while (nodeWalker.Next != tail)
                    nodeWalker = nodeWalker.Next;

                //if next stringnode is tail
                if (nodeWalker.Next == tail)
                {
                    tail = nodeWalker;
                    nodeWalker.Next = null;
                }
            }

            return popString;
        }
예제 #3
0
        //returns the number of strings currently held in the stack
        public int Count()
        {
            int        count      = 0;
            StringNode nodeWalker = head;

            while (nodeWalker != null)
            {
                count++;
                nodeWalker = nodeWalker.Next;
            }
            return(count);
        }
예제 #4
0
        //returns the most recently added string but does not remove it from the stack
        public String Peek()
        {
            StringNode peekNode = tail;

            if (isEmpty() == true)
            {
                throw new Exception("Nothing to Peek at. Stack is empty");
            }
            else
            {
                return(peekNode.Info);
            }
        }
예제 #5
0
        //Adds a string to the stack
        public void Push(String stringToAdd)
        {
            //new string node to add the string node info
            StringNode stringNodeToAdd = new StringNode(stringToAdd);

            //find where to add new node to
            if (isEmpty())
            {
                head = stringNodeToAdd;
                tail = stringNodeToAdd;
            }
            else
            {
                tail.Next = stringNodeToAdd;
                tail      = stringNodeToAdd;
            }
        }
예제 #6
0
 public Stack()
 {
     head = null;
     tail = null;
 }
예제 #7
0
        //Adds a string to the stack
        public void Push(String stringToAdd)
        {
            //new string node to add the string node info
            StringNode stringNodeToAdd = new StringNode(stringToAdd);

            //find where to add new node to
            if (isEmpty())
            {
                head = stringNodeToAdd;
                tail = stringNodeToAdd;
            }
            else
            {
                tail.Next = stringNodeToAdd;
                tail = stringNodeToAdd;
            }
        }
예제 #8
0
 public Stack()
 {
     head = null;
     tail = null;
 }
예제 #9
0
 public StringNode(String info)
 {
     Info = info;
     Next = null;
 }