// Removes and returns the CageNode at the front of the Queue.
        //  If there are no CageNodes in the Queue, throws a NullReferenceException.
        public CageNode Dequeue()
        {
            CageNode dqueued = null;

            try
            {
                if (Front != null)
                {
                    dqueued      = Front;
                    Front        = Front.Next;
                    dqueued.Next = null;
                }
                else
                {
                    throw new NullReferenceException();
                }
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("There are no CageNodes in this Queue.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(dqueued);
        }
 // Takes in a CageNode and adds it to the end of the Queue.
 //  If the Queue is empty, this CageNode becomes the new Front and End point for the Queue as its sole member.
 public void Enqueue(CageNode cageNode)
 {
     if (Front == null)
     {
         Front = cageNode;
         End   = cageNode;
     }
     else
     {
         End.Next = cageNode;
         End      = cageNode;
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Takes in an Animal object, and checks if it is a Cat or Dog. If it is a Cat or Dog, it places it into a new CageNode with the current
 ///      serial number, adds the CageNode to the Cats or Dogs Queue respectively, and iterates the NextSerial number, then returns true.
 ///     If the given Animal isn't a Cat or Dog, does nothing and returns false.
 /// </summary>
 /// <param name="animal"></param>
 /// <returns> Boolean indicating whether given animal was added to the Animal Shelter </returns>
 public bool Enqueue(Animal animal)
 {
     if (animal is Dog)
     {
         CageNode newCage = new CageNode(animal, NextSerial);
         Dogs.Enqueue(newCage);
         NextSerial++;
         return(true);
     }
     else if (animal is Cat)
     {
         CageNode newCage = new CageNode(animal, NextSerial);
         Cats.Enqueue(newCage);
         NextSerial++;
         return(true);
     }
     else
     {
         return(false);
     }
 }