コード例 #1
0
ファイル: AnimalShelter.cs プロジェクト: selmaT273/DSA
        public void EnqueueAnimal(PseudoNode animal)
        {
            All.Enqueue(animal);

            if (animal.Type == Animal.Cat)
            {
                Cats.Enqueue(animal);
            }
            else
            {
                Dogs.Enqueue(animal);
            }
        }
コード例 #2
0
ファイル: AnimalShelter.cs プロジェクト: selmaT273/DSA
        //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);
        }
コード例 #3
0
ファイル: AnimalShelter.cs プロジェクト: selmaT273/DSA
        //Add to the tail of the list.
        public void Enqueue(PseudoNode newItem)
        {
            if (count == 0)
            {
                head = newItem;
            }
            else
            {
                tail.Next = newItem;
            }

            tail = newItem;
            count++;
        }
コード例 #4
0
ファイル: AnimalShelter.cs プロジェクト: selmaT273/DSA
        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);
            }
        }
コード例 #5
0
ファイル: AnimalShelter.cs プロジェクト: selmaT273/DSA
        //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);
        }