Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 6
0
 public Stack()
 {
     head = null;
     tail = null;
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 8
0
 public Stack()
 {
     head = null;
     tail = null;
 }
Ejemplo n.º 9
0
 public StringNode(String info)
 {
     Info = info;
     Next = null;
 }