zoukankan      html  css  js  c++  java
  • 622 CircularQueue C#

    public class MyCircularQueue {
    
        int[] Queue=null;
        int _Front = 0;
        int _Rear = 0;
        int Length = 0;
        int Count = 0;
        /** Initialize your data structure here. Set the size of the queue to be k. */
        public MyCircularQueue(int k) {
            Queue = new int[k];
            _Front = 0;
            _Rear = 0;
            Count = 0;
            Length = k;
        }
        
        /** Insert an element into the circular queue. Return true if the operation is successful. */
        public bool EnQueue(int value) {
            if(IsFull())
                return false;
            
            Queue[_Rear] = value;
            
            _Rear++;
            _Rear = _Rear % Length;        
            
            Count++;        
            return true;
        }
        
        /** Delete an element from the circular queue. Return true if the operation is successful. */
        public bool DeQueue() {
            if(IsEmpty())
                return false;        
            
            _Front++;        
            _Front  = _Front % Length;
            Count--;
            return true;
        }
        
        /** Get the front item from the queue. */
        public int Front() {
            if(IsEmpty())
                return -1;
            return Queue[_Front];
        }
        
        /** Get the last item from the queue. */
        public int Rear() {     
            if(IsEmpty())
                return -1;
            int rear = _Rear - 1;
            if(rear == -1)
                rear = rear+Length;        
            return Queue[rear];
        }
        
        /** Checks whether the circular queue is empty or not. */
        public bool IsEmpty() {
            if(Count == 0)
                return true;
            return false;
        }
        
        /** Checks whether the circular queue is full or not. */
        public bool IsFull() {
            if(Count == Length)
                return true;
            return false;
        }
    }
    
    /**
     * Your MyCircularQueue object will be instantiated and called as such:
     * MyCircularQueue obj = new MyCircularQueue(k);
     * bool param_1 = obj.EnQueue(value);
     * 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();
     */
    
  • 相关阅读:
    X-CTF(REVERSE入门) python-trade
    X-CTF(REVERSE入门) getit
    X-CTF(REVERSE入门) csaw2013reversing2
    X-CTF(REVERSE入门) no-strings-attached
    X-CTF(REVERSE入门) insanity
    X-CTF(REVERSE入门) logmein
    面向对象编程的七大设计原则
    二叉树的性质
    Visual Studio 2017 WPF应用(.Net Freamwork)断点调试不命中的解决方法
    C语言读写文件
  • 原文地址:https://www.cnblogs.com/feipeng8848/p/10052935.html
Copyright © 2011-2022 走看看