mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 03:30:30 +08:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -6,16 +6,16 @@
|
||||
|
||||
#include "../include/include.h"
|
||||
|
||||
/* 双向链表结点 */
|
||||
/* 双向链表节点 */
|
||||
struct DoublyListNode {
|
||||
int val; // 结点值
|
||||
struct DoublyListNode *next; // 后继结点
|
||||
struct DoublyListNode *prev; // 前驱结点
|
||||
int val; // 节点值
|
||||
struct DoublyListNode *next; // 后继节点
|
||||
struct DoublyListNode *prev; // 前驱节点
|
||||
};
|
||||
|
||||
typedef struct DoublyListNode DoublyListNode;
|
||||
|
||||
/* 双向链表结点构造方法 */
|
||||
/* 双向链表节点构造方法 */
|
||||
DoublyListNode *newDoublyListNode(int num) {
|
||||
DoublyListNode* new = (DoublyListNode *) malloc(sizeof(DoublyListNode));
|
||||
new->val = num;
|
||||
@@ -24,14 +24,14 @@ DoublyListNode *newDoublyListNode(int num) {
|
||||
return new;
|
||||
}
|
||||
|
||||
/* 双向链表结点析构方法 */
|
||||
/* 双向链表节点析构方法 */
|
||||
void delDoublyListNode(DoublyListNode *node) {
|
||||
free(node);
|
||||
}
|
||||
|
||||
/* 基于双向链表实现的双向队列 */
|
||||
struct LinkedListDeque {
|
||||
DoublyListNode *front, *rear; // 头结点 front ,尾结点 rear
|
||||
DoublyListNode *front, *rear; // 头节点 front ,尾节点 rear
|
||||
int queSize; // 双向队列的长度
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ LinkedListDeque *newLinkedListDeque() {
|
||||
|
||||
/* 析构方法 */
|
||||
void delLinkedListdeque(LinkedListDeque *deque) {
|
||||
// 释放所有结点
|
||||
// 释放所有节点
|
||||
for (int i=0; i<deque->queSize && deque->front != NULL; i++) {
|
||||
DoublyListNode *tmp = deque->front;
|
||||
deque->front = deque->front->next;
|
||||
@@ -79,7 +79,7 @@ void push(LinkedListDeque *deque, int num, bool isFront) {
|
||||
// 将 node 添加至链表头部
|
||||
deque->front->prev = node;
|
||||
node->next = deque->front;
|
||||
deque->front = node;// 更新头结点
|
||||
deque->front = node;// 更新头节点
|
||||
}
|
||||
// 对尾入队操作
|
||||
else {
|
||||
@@ -120,25 +120,25 @@ int pop(LinkedListDeque *deque, bool isFront) {
|
||||
int val;
|
||||
// 队首出队操作
|
||||
if(isFront) {
|
||||
val = peekFirst(deque); // 暂存头结点值
|
||||
val = peekFirst(deque); // 暂存头节点值
|
||||
DoublyListNode *fNext = deque->front->next;
|
||||
if (fNext) {
|
||||
fNext->prev = NULL;
|
||||
deque->front->next = NULL;
|
||||
delDoublyListNode(deque->front);
|
||||
}
|
||||
deque->front = fNext; // 更新头结点
|
||||
deque->front = fNext; // 更新头节点
|
||||
}
|
||||
// 队尾出队操作
|
||||
else {
|
||||
val = peekLast(deque); // 暂存尾结点值
|
||||
val = peekLast(deque); // 暂存尾节点值
|
||||
DoublyListNode *rPrev = deque->rear->prev;
|
||||
if (rPrev) {
|
||||
rPrev->next = NULL;
|
||||
deque->rear->prev = NULL;
|
||||
delDoublyListNode(deque->rear);
|
||||
}
|
||||
deque->rear = rPrev; // 更新尾结点
|
||||
deque->rear = rPrev; // 更新尾节点
|
||||
}
|
||||
deque->queSize--; // 更新队列长度
|
||||
return val;
|
||||
|
||||
@@ -24,7 +24,7 @@ LinkedListQueue *newLinkedListQueue() {
|
||||
|
||||
/* 析构方法 */
|
||||
void delLinkedListQueue(LinkedListQueue *queue) {
|
||||
// 释放所有结点
|
||||
// 释放所有节点
|
||||
for (int i=0; i<queue->queSize && queue->front != NULL; i++) {
|
||||
ListNode *tmp = queue->front;
|
||||
queue->front = queue->front->next;
|
||||
@@ -46,14 +46,14 @@ bool empty(LinkedListQueue *queue) {
|
||||
|
||||
/* 入队 */
|
||||
void push(LinkedListQueue *queue, int num) {
|
||||
// 尾结点处添加 node
|
||||
// 尾节点处添加 node
|
||||
ListNode *node = newListNode(num);
|
||||
// 如果队列为空,则令头、尾结点都指向该结点
|
||||
// 如果队列为空,则令头、尾节点都指向该节点
|
||||
if (queue->front == NULL) {
|
||||
queue->front = node;
|
||||
queue->rear = node;
|
||||
}
|
||||
// 如果队列不为空,则将该结点添加到尾结点后
|
||||
// 如果队列不为空,则将该节点添加到尾节点后
|
||||
else {
|
||||
queue->rear->next = node;
|
||||
queue->rear = node;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
/* 基于链表实现的栈 */
|
||||
struct linkedListStack {
|
||||
ListNode *top; // 将头结点作为栈顶
|
||||
ListNode *top; // 将头节点作为栈顶
|
||||
int size; // 栈的长度
|
||||
};
|
||||
|
||||
@@ -55,8 +55,8 @@ int peek(linkedListStack *s) {
|
||||
void push(linkedListStack *s, int num) {
|
||||
assert(s);
|
||||
ListNode *node = (ListNode *) malloc(sizeof(ListNode));
|
||||
node->next = s->top; // 更新新加结点指针域
|
||||
node->val = num; // 更新新加结点数据域
|
||||
node->next = s->top; // 更新新加节点指针域
|
||||
node->val = num; // 更新新加节点数据域
|
||||
s->top = node; // 更新栈顶
|
||||
s->size++; // 更新栈大小
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user