<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                設計你的循環隊列實現。循環隊列是一種線性數據結構,其操作表現基于FIFO(先進先出)原則并且隊尾被連接在隊首之后以形成一個循環。它也被稱為“環形緩沖器” “。 循環隊列的一個好處是我們可以利用這個隊列之前用過的空間。在一個普通隊列里,一旦一個隊列滿了,我們就不能插入下一個元素,即使在隊列前面仍有空間。但是使用循環隊列,我們能使用這些空間去存儲新的值。 你的實現應該支持如下操作: * `MyCircularQueue(k)`:構造器,設置隊列長度為k。 * `Front`:從隊首獲取元素。如果隊列為空,返回-1。 * `Rear`:獲取隊尾元素。如果隊列為空,返回-1。 * `enQueue(value)`:向循環隊列插入一個元素。如果成功插入則返回真。 * `deQueue()`:從循環隊列中刪除一個元素。如果成功刪除則返回真。 * `isEmpty()`:檢查循環隊列是否為空。 * `isFull()`:檢查循環隊列是否已滿。 **示例:** ~~~ MyCircularQueue circularQueue = new MycircularQueue(3); //設置長度為3 circularQueue.enQueue(1); //返回true circularQueue.enQueue(2); //返回true circularQueue.enQueue(3); //返回true circularQueue.enQueue(4); //返回false,隊列已滿 circularQueue.Rear(); //返回3 circularQueue.isFull(); //返回true circularQueue.deQueue(); //返回true circularQueue.enQueue(4); //返回true circularQueue.Rear(); //返回4 ? ~~~ **提示:** * 所有的值都在0至1000的范圍內; * 操作數將在1至1000的范圍內; * * 請不要使用內置的隊列庫。 ``` /** * Initialize your data structure here. Set the size of the queue to be k. * @param {number} k */ var MyCircularQueue = function(k) { }; /** * Insert an element into the circular queue. Return true if the operation is successful. * @param {number} value * @return {boolean} */ MyCircularQueue.prototype.enQueue = function(value) { if(this.isFull()){ return false }else{ this.list[this.rear] = num; this.rear = (this.rear +1)%this.max; return true; } }; /** * Delete an element from the circular queue. Return true if the operation is successful. * @return {boolean} */ MyCircularQueue.prototype.deQueue = function() { let v= this.list[this.front]; this.list[this.front] = ''; this.front = (this.front+1)%this.max; return v; }; /** * Get the front item from the queue. * @return {number} */ MyCircularQueue.prototype.Front = function() { return this.list[this.front]; }; /** * Get the last item from the queue. * @return {number} */ MyCircularQueue.prototype.Rear = function() { let rear = this.rear - 1; return this.list[rear<0?this.max-1:rear] }; /** * Checks whether the circular queue is empty or not. * @return {boolean} */ MyCircularQueue.prototype.isEmpty = function() { return this.front === this.rear && !this.list[this.front]; }; /** * Checks whether the circular queue is full or not. * @return {boolean} */ MyCircularQueue.prototype.isFull = function() { return (this.front === this.rear) && this.list[this.front]; }; /** * Your MyCircularQueue object will be instantiated and called as such: * var obj = new MyCircularQueue(k) * var param_1 = obj.enQueue(value) * var param_2 = obj.deQueue() * var param_3 = obj.Front() * var param_4 = obj.Rear() * var param_5 = obj.isEmpty() * var param_6 = obj.isFull() */ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看