예제 #1
0
        public T PopBack()
        {
            if (Empty)
            {
                throw new Exception("Queue empty.");
            }

            LinkedElement <T> temp = first;


            while (temp.getParent() != last)
            {
                if (temp.getParent() == null)
                {
                    last  = null;
                    first = null;
                    return(temp.valor);
                }
                temp = temp.getParent();
            }

            temp.setParent(null);

            LinkedElement <T> temp2 = last;

            last = temp;
            return(temp2.valor);
        }
예제 #2
0
        public void Push(T valor)
        {
            if (valor == null)
            {
                throw new Exception("Invalid value: null");
            }
            LinkedElement <T> element = new LinkedElement <T>(valor);

            element.setParent(top);
            top = element;
        }
예제 #3
0
        public void Enter(T valor)
        {
            if (valor == null)
            {
                throw new Exception("Invalid value: null");
            }
            LinkedElement <T> element = new LinkedElement <T>(valor);

            if (first == null)
            {
                first = element;
            }
            if (last != null)
            {
                last.setParent(element);
            }
            last = element;
        }
예제 #4
0
        public void PushFront(T valor)
        {
            if (valor == null)
            {
                throw new Exception("Invalid value: null");
            }
            LinkedElement <T> element = new LinkedElement <T>(valor);

            if (first != null)
            {
                element.setParent(first);
            }
            else
            {
                last = element;
            }

            first = element;
        }