mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 18:00:18 +08:00
build
This commit is contained in:
@@ -4,7 +4,7 @@ comments: true
|
||||
|
||||
# 5.3 Double-ended queue
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
{ class="animation-figure" }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ comments: true
|
||||
|
||||
# 5.2 Queue
|
||||
|
||||
"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.
|
||||
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.
|
||||
|
||||
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."
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ comments: true
|
||||
|
||||
# 5.1 Stack
|
||||
|
||||
A "Stack" is a linear data structure that follows the principle of Last-In-First-Out (LIFO).
|
||||
A <u>stack</u> is a linear data structure that follows the principle of Last-In-First-Out (LIFO).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ A double-ended queue, which is a combination of a stack and a queue or two stack
|
||||
|
||||
**Q**: How exactly are undo and redo implemented?
|
||||
|
||||
Undo and redo operations are implemented using two stacks: Stack A for undo and Stack B for redo.
|
||||
Undo and redo operations are implemented using two stacks: Stack `A` for undo and Stack `B` for redo.
|
||||
|
||||
1. Each time a user performs an operation, it is pushed onto Stack A, and Stack B is cleared.
|
||||
2. When the user executes an "undo", the most recent operation is popped from Stack A and pushed onto Stack B.
|
||||
3. When the user executes a "redo", the most recent operation is popped from Stack B and pushed back onto Stack A.
|
||||
1. Each time a user performs an operation, it is pushed onto Stack `A`, and Stack `B` is cleared.
|
||||
2. When the user executes an "undo", the most recent operation is popped from Stack `A` and pushed onto Stack `B`.
|
||||
3. When the user executes a "redo", the most recent operation is popped from Stack `B` and pushed back onto Stack `A`.
|
||||
|
||||
Reference in New Issue
Block a user