|
|
@ -3933,7 +3933,7 @@
|
|
|
|
<p>回顾上一节内容,我们使用普通单向链表来实现队列,因为它可以方便地删除头节点(对应出队操作)和在尾节点后添加新节点(对应入队操作)。</p>
|
|
|
|
<p>回顾上一节内容,我们使用普通单向链表来实现队列,因为它可以方便地删除头节点(对应出队操作)和在尾节点后添加新节点(对应入队操作)。</p>
|
|
|
|
<p>对于双向队列而言,头部和尾部都可以执行入队和出队操作。换句话说,双向队列需要实现另一个对称方向的操作。为此,我们采用“双向链表”作为双向队列的底层数据结构。</p>
|
|
|
|
<p>对于双向队列而言,头部和尾部都可以执行入队和出队操作。换句话说,双向队列需要实现另一个对称方向的操作。为此,我们采用“双向链表”作为双向队列的底层数据结构。</p>
|
|
|
|
<p>如图 5-8 所示,我们将双向链表的头节点和尾节点视为双向队列的队首和队尾,同时实现在两端添加和删除节点的功能。</p>
|
|
|
|
<p>如图 5-8 所示,我们将双向链表的头节点和尾节点视为双向队列的队首和队尾,同时实现在两端添加和删除节点的功能。</p>
|
|
|
|
<div class="tabbed-set tabbed-alternate" data-tabs="2:5"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><input id="__tabbed_2_3" name="__tabbed_2" type="radio" /><input id="__tabbed_2_4" name="__tabbed_2" type="radio" /><input id="__tabbed_2_5" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">LinkedListDeque</label><label for="__tabbed_2_2">pushLast()</label><label for="__tabbed_2_3">pushFirst()</label><label for="__tabbed_2_4">popLast()</label><label for="__tabbed_2_5">popFirst()</label></div>
|
|
|
|
<div class="tabbed-set tabbed-alternate" data-tabs="2:5"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><input id="__tabbed_2_3" name="__tabbed_2" type="radio" /><input id="__tabbed_2_4" name="__tabbed_2" type="radio" /><input id="__tabbed_2_5" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">LinkedListDeque</label><label for="__tabbed_2_2">push_last()</label><label for="__tabbed_2_3">push_first()</label><label for="__tabbed_2_4">pop_last()</label><label for="__tabbed_2_5">pop_first()</label></div>
|
|
|
|
<div class="tabbed-content">
|
|
|
|
<div class="tabbed-content">
|
|
|
|
<div class="tabbed-block">
|
|
|
|
<div class="tabbed-block">
|
|
|
|
<p><a class="glightbox" href="../deque.assets/linkedlist_deque.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="基于链表实现双向队列的入队出队操作" class="animation-figure" src="../deque.assets/linkedlist_deque.png" /></a></p>
|
|
|
|
<p><a class="glightbox" href="../deque.assets/linkedlist_deque.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="基于链表实现双向队列的入队出队操作" class="animation-figure" src="../deque.assets/linkedlist_deque.png" /></a></p>
|
|
|
@ -5552,7 +5552,7 @@
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<h3 id="2">2. 基于数组的实现<a class="headerlink" href="#2" title="Permanent link">¶</a></h3>
|
|
|
|
<h3 id="2">2. 基于数组的实现<a class="headerlink" href="#2" title="Permanent link">¶</a></h3>
|
|
|
|
<p>如图 5-9 所示,与基于数组实现队列类似,我们也可以使用环形数组来实现双向队列。</p>
|
|
|
|
<p>如图 5-9 所示,与基于数组实现队列类似,我们也可以使用环形数组来实现双向队列。</p>
|
|
|
|
<div class="tabbed-set tabbed-alternate" data-tabs="4:5"><input checked="checked" id="__tabbed_4_1" name="__tabbed_4" type="radio" /><input id="__tabbed_4_2" name="__tabbed_4" type="radio" /><input id="__tabbed_4_3" name="__tabbed_4" type="radio" /><input id="__tabbed_4_4" name="__tabbed_4" type="radio" /><input id="__tabbed_4_5" name="__tabbed_4" type="radio" /><div class="tabbed-labels"><label for="__tabbed_4_1">ArrayDeque</label><label for="__tabbed_4_2">pushLast()</label><label for="__tabbed_4_3">pushFirst()</label><label for="__tabbed_4_4">popLast()</label><label for="__tabbed_4_5">popFirst()</label></div>
|
|
|
|
<div class="tabbed-set tabbed-alternate" data-tabs="4:5"><input checked="checked" id="__tabbed_4_1" name="__tabbed_4" type="radio" /><input id="__tabbed_4_2" name="__tabbed_4" type="radio" /><input id="__tabbed_4_3" name="__tabbed_4" type="radio" /><input id="__tabbed_4_4" name="__tabbed_4" type="radio" /><input id="__tabbed_4_5" name="__tabbed_4" type="radio" /><div class="tabbed-labels"><label for="__tabbed_4_1">ArrayDeque</label><label for="__tabbed_4_2">push_last()</label><label for="__tabbed_4_3">push_first()</label><label for="__tabbed_4_4">pop_last()</label><label for="__tabbed_4_5">pop_first()</label></div>
|
|
|
|
<div class="tabbed-content">
|
|
|
|
<div class="tabbed-content">
|
|
|
|
<div class="tabbed-block">
|
|
|
|
<div class="tabbed-block">
|
|
|
|
<p><a class="glightbox" href="../deque.assets/array_deque.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="基于数组实现双向队列的入队出队操作" class="animation-figure" src="../deque.assets/array_deque.png" /></a></p>
|
|
|
|
<p><a class="glightbox" href="../deque.assets/array_deque.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="基于数组实现双向队列的入队出队操作" class="animation-figure" src="../deque.assets/array_deque.png" /></a></p>
|
|
|
|