示例#1
0
 //dequeue
 /// <summary>
 /// this will dequeue from a queue, but just done with an animal object
 /// </summary>
 /// <returns>a node that has an onimal object</returns>
 public AnimalNode Dequeue()
 {
     //should add check if trying to dequeue from an empty queue
     if (Front == null)
     {
         return(null);
     }
     else
     {
         AnimalNode temp = Front;
         Front     = Front.Next;
         temp.Next = null;
         return(temp);
     }
 }
示例#2
0
 //enqueue
 /// <summary>
 /// this will enqueue into a queue but with an animal object
 /// </summary>
 /// <param name="value">an animal object</param>
 public void Enqueue(Animal value)
 {
     if (Front == null) //if queue was empty and I add one
     {
         AnimalNode newNode = new AnimalNode(value);
         Rear  = newNode; //is this redundent because this should have happened in the instatiate with value because of line above
         Front = newNode; //is this redundent
     }
     else
     {
         AnimalNode newNode = new AnimalNode(value);
         Rear.Next = newNode;
         Rear      = newNode;
     }
 }
示例#3
0
 //dequeue, this is where there is a param to check adopter's pref
 /// <summary>
 /// checks if the animal user is looking for is in shelter
 /// </summary>
 /// <param name="pref">what animal is the user searching for</param>
 /// <returns>if the animal is in the shelter, returns the animal, else null</returns>
 public AnimalNode ShelterDequeue(Animal pref)
 {
     if (AnimalQueue1.Peek() == null && AnimalQueue2.Peek() == null) //shelter is empty
     {
         return(null);
     }
     else
     {
         while (AnimalQueue1.Peek() != null)
         {
             if (AnimalQueue1.Peek().AnimalValue.AnimalProp == pref.AnimalProp)
             {
                 AnimalNode returnAnimal = new AnimalNode();
                 returnAnimal = AnimalQueue1.Dequeue();
                 //moves remainder of queue to other queue to keep correct order
                 while (AnimalQueue1.Peek() != null)
                 {
                     AnimalNode tempAnimal = new AnimalNode();
                     tempAnimal = AnimalQueue1.Dequeue();
                     AnimalQueue2.Enqueue(tempAnimal.AnimalValue);
                 }
                 //my design pushes it back to the first queue because of how I add to the shelter
                 while (AnimalQueue2.Peek() != null)
                 {
                     AnimalNode tempAnimal = new AnimalNode();
                     tempAnimal = AnimalQueue2.Dequeue();
                     AnimalQueue1.Enqueue(tempAnimal.AnimalValue);
                 }
                 return(returnAnimal);
             }
             else
             {
                 AnimalNode tempAnimal = new AnimalNode();
                 tempAnimal = AnimalQueue1.Dequeue();
                 AnimalQueue2.Enqueue(tempAnimal.AnimalValue);
             }
         }
         return(null);
     }
 }
示例#4
0
 public AnimalQueue(AnimalNode node)
 {
     Front = node;
     Rear  = node;
 }
示例#5
0
 //instantiate (with and without starter "node")
 public AnimalQueue()
 {
     Front = null;
     Rear  = null;
 }
示例#6
0
 public AnimalNode(Animal value)
 {
     AnimalValue = value;
     Next        = null;
 }