mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 11:41:22 +08:00
translation: Update the figures for the chapter of stack and queue (#1084)
* Update the figures for the chapter of stack and queue * Bug fixes and reducing file size
This commit is contained in:
@@ -321,13 +321,13 @@ To implement a queue, we need a data structure that allows adding elements at on
|
||||
As shown in the figure below, we can consider the "head node" and "tail node" of a linked list as the "head" and "tail" of the queue, respectively. We restrict the operations so that nodes can only be added at the tail and removed at the head.
|
||||
|
||||
=== "LinkedListQueue"
|
||||

|
||||

|
||||
|
||||
=== "push()"
|
||||

|
||||

|
||||
|
||||
=== "pop()"
|
||||

|
||||

|
||||
|
||||
Below is the code for implementing a queue using a linked list:
|
||||
|
||||
@@ -349,13 +349,13 @@ With this design, **the effective interval of elements in the array is `[front,
|
||||
Both enqueue and dequeue operations only require a single operation, each with a time complexity of $O(1)$.
|
||||
|
||||
=== "ArrayQueue"
|
||||

|
||||

|
||||
|
||||
=== "push()"
|
||||

|
||||

|
||||
|
||||
=== "pop()"
|
||||

|
||||

|
||||
|
||||
You might notice a problem: as enqueue and dequeue operations are continuously performed, both `front` and `rear` move to the right and **will eventually reach the end of the array and can't move further**. To resolve this issue, we can treat the array as a "circular array."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user