This commit is contained in:
krahets
2024-05-02 01:46:20 +08:00
parent 5e90519796
commit 23353e7960
324 changed files with 420 additions and 419 deletions
+2 -2
View File
@@ -3657,7 +3657,7 @@
<!-- Page content -->
<h1 id="53-double-ended-queue">5.3 &nbsp; Double-ended queue<a class="headerlink" href="#53-double-ended-queue" title="Permanent link">&para;</a></h1>
<p>In a queue, we can only delete elements from the head or add elements to the tail. As shown in the following diagram, a "double-ended queue (deque)" offers more flexibility, allowing the addition or removal of elements at both the head and the tail.</p>
<p>In a queue, we can only delete elements from the head or add elements to the tail. As shown in the following diagram, a <u>double-ended queue (deque)</u> offers more flexibility, allowing the addition or removal of elements at both the head and the tail.</p>
<p><a class="glightbox" href="../deque.assets/deque_operations.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Operations in double-ended queue" class="animation-figure" src="../deque.assets/deque_operations.png" /></a></p>
<p align="center"> Figure 5-7 &nbsp; Operations in double-ended queue </p>
@@ -7494,7 +7494,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>
+1 -1
View File
@@ -3724,7 +3724,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>
+2 -2
View File
@@ -3657,7 +3657,7 @@
<!-- Page content -->
<h1 id="52-queue">5.2 &nbsp; Queue<a class="headerlink" href="#52-queue" title="Permanent link">&para;</a></h1>
<p>"Queue" is a linear data structure that follows the First-In-First-Out (FIFO) rule. As the name suggests, a queue simulates the phenomenon of lining up, where newcomers join the queue at the rear, and the person at the front leaves the queue first.</p>
<p>A <u>queue</u> is a linear data structure that follows the First-In-First-Out (FIFO) rule. As the name suggests, a queue simulates the phenomenon of lining up, where newcomers join the queue at the rear, and the person at the front leaves the queue first.</p>
<p>As shown in Figure 5-4, we call the front of the queue the "head" and the back the "tail." The operation of adding elements to the rear of the queue is termed "enqueue," and the operation of removing elements from the front is termed "dequeue."</p>
<p><a class="glightbox" href="../queue.assets/queue_operations.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Queue's first-in-first-out rule" class="animation-figure" src="../queue.assets/queue_operations.png" /></a></p>
<p align="center"> Figure 5-4 &nbsp; Queue's first-in-first-out rule </p>
@@ -6194,7 +6194,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>
+2 -2
View File
@@ -3675,7 +3675,7 @@
<!-- Page content -->
<h1 id="51-stack">5.1 &nbsp; Stack<a class="headerlink" href="#51-stack" title="Permanent link">&para;</a></h1>
<p>A "Stack" is a linear data structure that follows the principle of Last-In-First-Out (LIFO).</p>
<p>A <u>stack</u> is a linear data structure that follows the principle of Last-In-First-Out (LIFO).</p>
<p>We can compare a stack to a pile of plates on a table. To access the bottom plate, one must first remove the plates on top. By replacing the plates with various types of elements (such as integers, characters, objects, etc.), we obtain the data structure known as a stack.</p>
<p>As shown in Figure 5-1, we refer to the top of the pile of elements as the "top of the stack" and the bottom as the "bottom of the stack." The operation of adding elements to the top of the stack is called "push," and the operation of removing the top element is called "pop."</p>
<p><a class="glightbox" href="../stack.assets/stack_operations.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="Stack's last-in-first-out rule" class="animation-figure" src="../stack.assets/stack_operations.png" /></a></p>
@@ -5721,7 +5721,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>
@@ -3607,11 +3607,11 @@
<p><strong>Q</strong>: A double-ended queue seems like two stacks joined together. What are its uses?</p>
<p>A double-ended queue, which is a combination of a stack and a queue or two stacks joined together, exhibits both stack and queue logic. Thus, it can implement all applications of stacks and queues while offering more flexibility.</p>
<p><strong>Q</strong>: How exactly are undo and redo implemented?</p>
<p>Undo and redo operations are implemented using two stacks: Stack A for undo and Stack B for redo.</p>
<p>Undo and redo operations are implemented using two stacks: Stack <code>A</code> for undo and Stack <code>B</code> for redo.</p>
<ol>
<li>Each time a user performs an operation, it is pushed onto Stack A, and Stack B is cleared.</li>
<li>When the user executes an "undo", the most recent operation is popped from Stack A and pushed onto Stack B.</li>
<li>When the user executes a "redo", the most recent operation is popped from Stack B and pushed back onto Stack A.</li>
<li>Each time a user performs an operation, it is pushed onto Stack <code>A</code>, and Stack <code>B</code> is cleared.</li>
<li>When the user executes an "undo", the most recent operation is popped from Stack <code>A</code> and pushed onto Stack <code>B</code>.</li>
<li>When the user executes a "redo", the most recent operation is popped from Stack <code>B</code> and pushed back onto Stack <code>A</code>.</li>
</ol>
<!-- Source file information -->
@@ -3800,7 +3800,7 @@ aria-label="Footer"
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright &copy; 2022-2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
Copyright &copy; 2024 krahets<br>The website content is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>
</div>