public void CanDequeueEmpty()
        {
            //Arrange
            Node node = new Node()
            {
                Value = 4
            };

            MyQueue queue = new MyQueue(node);

            //Act

            //Assert

            Assert.Equal(4, queue.Dequeue().Value);
        }
        public void CanDequeueEmpty2()
        {
            //Arrange
            Node node = new Node()
            {
                Value = 4
            };

            MyQueue queue = new MyQueue(node);

            //Act
            Node dummy = queue.Dequeue();  //Pop completely empty

            //Assert

            Assert.Equal(null, queue.Dequeue().Next);
        }
        public void CanDequeue()
        {
            //Arrange
            Node node = new Node()
            {
                Value = 4
            };
            Node node2 = new Node()
            {
                Value = 8
            };
            Node node3 = new Node()
            {
                Value = 15
            };
            Node node4 = new Node()
            {
                Value = 16
            };
            Node node5 = new Node()
            {
                Value = 23
            };
            Node node6 = new Node()
            {
                Value = 42
            };

            MyQueue queue = new MyQueue(node);

            queue.Enqueue(node2);
            queue.Enqueue(node3);
            queue.Enqueue(node4);
            queue.Enqueue(node5);
            queue.Enqueue(node6);

            //Act

            //Assert
            // 4 is the first item entered, so it should be the one Enqueued
            Assert.Equal(4, actual: queue.Dequeue().Value);
        }
예제 #4
0
        /// <summary>
        /// Заполнение данных из консоли
        /// </summary>
        /// <param name="persons"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        static bool FillQueueFromConcole(ref MyQueue <Person> persons, out int count)
        {
            Console.WriteLine("Введите данные:");
            string[] phones = Console.ReadLine().Split(' ');

            if (!int.TryParse(phones[0], out count))
            {
                return(false);
            }


            for (int i = 1; i < phones.Length; i++)
            {
                Person person = new Person(phones[i]);
                person.Id = i;
                persons.enqueue(person);
            }

            return(true);
        }
예제 #5
0
        static void Main(string[] args)
        {
            MyQueue <Person> persons = new MyQueue <Person>();

            int  count     = 0;
            bool isCorrect = false;

            while (!isCorrect)
            {
                try
                {
                    //Заполнение данных
                    isCorrect = FillQueueFromConcole(ref persons, out count);

                    //Вывод данных
                    string output = "";
                    for (int i = 0; i < count; i++)
                    {
                        output += persons.dequeue().PhoneNumber + " ";
                    }
                    Console.Write(output);
                }
                catch (Exception ex)
                {
                    isCorrect = false;
                    Console.WriteLine(ex.Message);
                }
                if (!isCorrect)
                {
                    Console.WriteLine("Вы хотите ввести данные еще раз?(y/n)");

                    if (Console.ReadLine() != "y")
                    {
                        return;
                    }
                }
            }
            Console.ReadKey();
        }