Example #1
0
        public void EnqueueAnimal(PseudoNode animal)
        {
            All.Enqueue(animal);

            if (animal.Type == Animal.Cat)
            {
                Cats.Enqueue(animal);
            }
            else
            {
                Dogs.Enqueue(animal);
            }
        }
Example #2
0
        //Remove from the head of the list.
        public PseudoNode Dequeue()
        {
            PseudoNode dequeued = null;
            PseudoNode current  = head;

            if (count > 0)
            {
                dequeued = head;
                head     = head.Next;
                count--;
            }

            return(dequeued);
        }
Example #3
0
        //Add to the tail of the list.
        public void Enqueue(PseudoNode newItem)
        {
            if (count == 0)
            {
                head = newItem;
            }
            else
            {
                tail.Next = newItem;
            }

            tail = newItem;
            count++;
        }
Example #4
0
        public void DequeueAny(PseudoNode item)
        {
            //Remove from the all list.
            var animal = All.Dequeue();

            //Then remove from either the dog list or cat list.
            if (animal.Type == Animal.Cat)
            {
                Cats.DequeueAny(animal);
            }
            else
            {
                Dogs.DequeueAny(animal);
            }
        }
Example #5
0
        //Remove any element from the list at any position.
        public PseudoNode DequeueAny(PseudoNode item)
        {
            PseudoNode current  = head;
            PseudoNode previous = null;

            PseudoNode dequeued = null;

            while (current != null)
            {
                PseudoNode next = current.Next;

                if (current == item)
                {
                    dequeued = current;

                    if (previous == null)
                    {
                        head    = next;
                        current = null;
                        break;
                    }
                    else
                    {
                        //Copy down the next pointer into the current node
                        //to override it. Otherwise it will still be in the
                        //list when setting previous in line 101.
                        current       = next;
                        previous.Next = current;

                        //Adjust the tail
                        if (current.Next == null)
                        {
                            tail = current;
                        }
                    }

                    count--;
                }

                previous = current;
                current  = current.Next;
            }


            return(dequeued);
        }