Update stack and queue.

This commit is contained in:
Yudong Jin
2022-11-30 02:27:26 +08:00
parent 53cc651af2
commit 8669e06414
24 changed files with 705 additions and 186 deletions

View File

@@ -60,6 +60,7 @@ comments: true
/* 判断队列是否为空 */
boolean isEmpty = queue.isEmpty();
System.out.println("队列是否为空 = " + isEmpty);
```
=== "C++"
@@ -145,10 +146,9 @@ comments: true
```java title="array_queue.java"
/* 基于环形数组实现的队列 */
class ArrayQueue {
int[] nums; // 用于存储队列元素的数组
int size = 0; // 队列长度(即元素个数)
int front = 0; // 指针,指向队
int rear = 0; // 尾指针,指向队尾 + 1
private int[] nums; // 用于存储队列元素的数组
private int front = 0; // 头指针,指向队首
private int rear = 0; // 指针,指向队尾 + 1
public ArrayQueue(int capacity) {
// 初始化数组