public static void Main()
        {
            var queue = new MyQueue <int>(1);

            queue.Enqueue(3);
            queue.Enqueue(5);
            queue.Enqueue(4);

            Console.WriteLine(queue.Peek());
            Console.WriteLine(queue.Dequeue());
            Console.WriteLine(queue.Dequeue());
        }
        static void Main(string[] args)
        {
            // Declare and populate the nodes
            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, Next = null
            };                                                   // Point last item on queue to null.  Necessary for passing unit tests.
            Node node7 = new Node();

            // Instatiate the queue
            MyQueue queue = new MyQueue(node);

            // Populate the queue
            queue.Enqueue(node2);
            queue.Enqueue(node3);
            queue.Enqueue(node4);
            queue.Enqueue(node5);
            queue.Enqueue(node6);

            queue.PrintAllNodes(); // Print the queue before the dequeue

            node7 = queue.Dequeue();
            Console.WriteLine($"Dequed {node7.Value}");

            queue.PrintAllNodes(); // Print the queue after the dequeue

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var myQueue = new MyQueue <int>();

            myQueue.Enqueue(1);
            myQueue.Enqueue(2);
            myQueue.Enqueue(3);
            myQueue.Enqueue(4);
            myQueue.Enqueue(5);

            Console.WriteLine(myQueue.Dequeue());
            Console.WriteLine(myQueue.Peek());
            Console.WriteLine(myQueue.Dequeue());

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            MyQueue <int> a = new MyQueue <int>();

            a.Enqueue(2);
            a.Enqueue(3);
            a.Enqueue(4);
            a.Enqueue(5);
            a.Enqueue(6);
            a.Enqueue(7);
            a.Enqueue(8);

            a.Dequeue();
            a.Dequeue();
            a.Dequeue();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            List <int> list = new List <int> {
                3, 5, 2, 666, -1, -1
            };
            MyQueue <int> queue = new MyQueue <int>(list);

            WriteLine(queue);

            WriteLine(queue.Top());
            WriteLine(queue.Pop());
            WriteLine(queue.Pop());

            queue.Push(12);
            queue.Push(21);

            WriteLine(queue);
        }
Exemplo n.º 6
0
        static void YangHui(int n)
        {
            MyQueue <int> qq = new MyQueue <int>(n + 1);

            Console.WriteLine(1);
            qq.InQueue(0);
            qq.InQueue(1);
            for (int i = 2; i <= n; i++)
            {
                qq.InQueue(0);
                int[] s = new int[i];
                for (int j = 0; j < i; j++)
                {
                    s[j] = qq.OutQueue() + qq.GetFirst();
                    Console.Write(s[j]);
                    Console.Write(' ');
                    qq.InQueue(s[j]);
                }
                Console.WriteLine();
            }
        }
Exemplo n.º 7
0
            static void Main(string[] args)
            {
                MyQueue q = new MyQueue();

                q.enqueue(new Node(32));
                q.enqueue(new Node(15));
                q.enqueue(new Node(19));
                q.enqueue(new Node(78));

                q.print();
                Console.WriteLine("Min Value:{0}", q.getMin());


                Node min = q.getMinNode();

                Console.WriteLine("Min Value via node:{0}", min.value);


                Console.WriteLine("Now extracting the min value and printing the Queue...");
                Node other_min = q.extract_min();

                q.print();
            }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var myQueue = new MyQueue <int>();

            myQueue.Enqueue(1);
            myQueue.Enqueue(2);
            myQueue.Enqueue(3);
            myQueue.Enqueue(4);

            foreach (int i in myQueue.ToArray())
            {
                Console.WriteLine(i);
            }

            Console.WriteLine();

            while (myQueue.Count > 0)
            {
                Console.WriteLine(myQueue.Dequeue());
            }

            Console.ReadKey();
        }
Exemplo n.º 9
0
        /// <summary>
        /// 初始化并运行简单自定义队列
        /// </summary>
        public static void BuildAndRunQueue()
        {
            MyQueue queue = new MyQueue();

            queue.EnQueue(1);
            queue.EnQueue(2);
            queue.EnQueue(3);
            queue.EnQueue(4);
            queue.EnQueue(5);
            queue.EnQueue(6);

            for (int i = 0; i < 8; i++)
            {
                queue.DeQueue();
                if (!queue.IsEmpty())
                {
                    Console.WriteLine(queue.Front());
                }
                else
                {
                    Console.WriteLine("队列为空!");
                }
            }
        }