예제 #1
0
        static void Main(string[] args)
        {
            MovingAverage movingAverage = new MovingAverage(3);

            movingAverage.Next(1);
            movingAverage.Next(10);
            movingAverage.Next(3);
            movingAverage.Next(5);

            #region Queue
            Queue queue = new Queue(5);
            queue.Enqueue(10);
            queue.Enqueue(20);
            queue.Enqueue(30);
            queue.Enqueue(40);
            queue.PrintQueue();
            queue.Dequeue();
            #endregion

            #region Circular Queue

            //Your MyCircularQueue object will be instantiated and called as such:
            MyCircularQueue obj     = new MyCircularQueue(5);
            bool            param_1 = obj.EnQueue(2);
            bool            param_2 = obj.DeQueue();
            int             param_3 = obj.Front();
            int             param_4 = obj.Rear();
            bool            param_5 = obj.IsEmpty();
            bool            param_6 = obj.IsFull();

            #endregion
        }
예제 #2
0
        /// <summary>
        /// 初始化并运行自定义循环队列
        /// </summary>
        public static void BuildAndRunCircularQueue()
        {
            MyCircularQueue myCircularQueue = new MyCircularQueue(5);

            Console.WriteLine(myCircularQueue.DeQueue());
            Console.WriteLine(myCircularQueue.EnQueue(1));
            Console.WriteLine(myCircularQueue.EnQueue(2));
            Console.WriteLine(myCircularQueue.EnQueue(3));
            Console.WriteLine(myCircularQueue.EnQueue(4));
            Console.WriteLine(myCircularQueue.EnQueue(5));
            Console.WriteLine(myCircularQueue.EnQueue(6));
            Console.WriteLine(myCircularQueue.EnQueue(7));
            Console.WriteLine(myCircularQueue.DeQueue());
            Console.WriteLine(myCircularQueue.EnQueue(10));
        }