Example #1
0
        /// <summary>
        /// Dequeueing the oldest cat
        /// </summary>
        /// <returns>Oldest entered cat</returns>
        public CatDog dequeueCat()
        {
            Node lastCat = null;

            Node temp = queue.head;

            while (temp != null)
            {
                if (((CatDog)temp.Data).type == CatDogType.Cat)
                {
                    lastCat = temp;
                }

                temp = temp.Next;
            }

            if (lastCat.Next == null)
            {
                return((CatDog)queue.DeleteEnd());
            }
            else
            {
                CatDog del = (CatDog)lastCat.Data;
                lastCat.Data = lastCat.Next.Data;
                lastCat.Next = lastCat.Next.Next;

                return(del);
            }
        }
        public CatDog dequeue(CatDog pref)
        {
            Queue <CatDog> tempQ       = new Queue <CatDog>();
            Node <CatDog>  removedNode = new Node <CatDog>();
            Node <CatDog>  savedNode   = new Node <CatDog>();
            bool           found       = false;

            if (Shelter.IsEmpty())
            {
                throw new NullReferenceException();
            }
            else
            {
                while (!Shelter.IsEmpty())
                {
                    removedNode = Shelter.Dequeue();

                    // Saves the first pref found and makes sure it will only be found once
                    if (removedNode.Value.Equals(pref) && !found)
                    {
                        savedNode = removedNode;
                        found     = true;
                    }
                    // Adds the removed Nodes into a new Queue to ensure no loss of data
                    else
                    {
                        tempQ.Enqueue(removedNode.Value);
                    }
                }// end while

                // Makes Shelter equal to the new list
                Shelter = tempQ;
                return(savedNode.Value);
            }
        }// end dequeue
Example #3
0
        public void Cat_Success()
        {
            var cat = CatDog.Cat().Result;

            Assert.IsNotNull(cat);
            Assert.IsFalse(cat.IsNullOrWhiteSpace());
            Assert.IsTrue(cat.StartsWith("http://random.cat/i/"));
        }
Example #4
0
        public void Dog_Success()
        {
            var dog = CatDog.Dog().Result;

            Assert.IsNotNull(dog);
            Assert.IsFalse(dog.IsNullOrWhiteSpace());
            Assert.IsTrue(dog.StartsWith("http://random.dog/"));
        }
Example #5
0
        /// <summary>
        /// <param name="d"> Cat/Dog Number </param>
        /// <param name="c"> Type - Cat or Dog </param>
        /// </summary>
        public void enqueue(object d, CatDogType c)
        {
            CatDog cd = new CatDog((int)d, c);

            queue.Insert(cd);
        }
 public void enqueue(CatDog animal)
 {
     Shelter.Enqueue(animal);
 }