From 264bc71c87541e5fea312c6881bb592fcc014cd5 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:25:42 +0000 Subject: [PATCH 01/14] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E5=A4=8D=E5=88=B6=20=E7=BB=99=E4=BD=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=95=BF=E5=BA=A6=E4=B8=BA=20n=20=E7=9A=84=E9=93=BE?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E6=AF=8F=E4=B8=AA=E8=8A=82=E7=82=B9=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E4=B8=80=E4=B8=AA=E9=A2=9D=E5=A4=96=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=9A=84=E9=9A=8F=E6=9C=BA=E6=8C=87=E9=92=88=20random=20?= =?UTF-8?q?=EF=BC=8C=E8=AF=A5=E6=8C=87=E9=92=88=E5=8F=AF=E4=BB=A5=E6=8C=87?= =?UTF-8?q?=E5=90=91=E9=93=BE=E8=A1=A8=E4=B8=AD=E7=9A=84=E4=BB=BB=E4=BD=95?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=88=96=E7=A9=BA=E8=8A=82=E7=82=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节点的 next 指针和 random 指针也都应指向复制链表中的新节点,并使原链表和复制链表中的这些指针能够表示相同的链表状态。复制链表中的指针都不应指向原链表中的节点 。 例如,如果原链表中有 X 和 Y 两个节点,其中 X.random --> Y 。那么在复制链表中对应的两个节点 x 和 y ,同样有 x.random --> y 。 返回复制链表的头节点。 Signed-off-by: LUHAN <3041492091@qq.com> --- OJ-list1 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 OJ-list1 diff --git a/OJ-list1 b/OJ-list1 new file mode 100644 index 0000000..cf9ceaf --- /dev/null +++ b/OJ-list1 @@ -0,0 +1,65 @@ +/** + * Definition for a Node. + * struct Node { + * int val; + * struct Node *next; + * struct Node *random; + * }; + */ + +struct Node* copyRandomList(struct Node* head) { + typedef struct Node Node; + +Node *cur=head,*copy; +//复制节点并插到节点后 +while(cur) +{ +//复制 +copy=(Node*)malloc(sizeof(Node)); +copy->val=cur->val; +//插入 +copy->next=cur->next; +cur->next=copy; +//跳转下个节点 +cur=copy->next; + +} + +cur=head; +//利用random->next是copy的节点复制原链表random +while(cur) +{ +copy=cur->next; +if(cur->random==NULL) +{ + copy->random=NULL; +} +else +{ + copy->random=cur->random->next; +} +cur=copy->next; +} + +// 完成复制,记得重置cur到head +cur=head; +//将copy的节点重新连接到一个新的头结点(可以不管原链表的复原) +Node* newhead=NULL,*tail=NULL; +while(cur) +{ +copy=cur->next; +//无哨兵位尾插节点常规操作 +if(tail==NULL) +{ + newhead=tail=copy; +} +else +{ + tail->next=copy; + tail=tail->next; +} +cur=copy->next; +} + +return newhead; +} \ No newline at end of file -- Gitee From df6052e6a6fb4854242c4746b007495cef4fb182 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:50:09 +0000 Subject: [PATCH 02/14] =?UTF-8?q?=E7=8E=AF=E5=BD=A2=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E5=88=A4=E6=96=AD=20=E5=BF=AB=E6=85=A2=E6=8C=87=E9=92=88?= =?UTF-8?q?=E7=9A=84=E8=BF=90=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LUHAN <3041492091@qq.com> --- OJ-circlelist1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 OJ-circlelist1 diff --git a/OJ-circlelist1 b/OJ-circlelist1 new file mode 100644 index 0000000..e3a11a7 --- /dev/null +++ b/OJ-circlelist1 @@ -0,0 +1,13 @@ +bool hasCycle(struct ListNode *head) +{ +struct ListNode* fast=head,* slow=head; + +while(fast&&fast->next) +{ + fast=fast->next->next; + slow=slow->next; + if(slow==fast) + return true; +} +return false; +} \ No newline at end of file -- Gitee From 5e372edfde76ac3c4cd5986d5fb6a4624621e8f3 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:50:53 +0000 Subject: [PATCH 03/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Li?= =?UTF-8?q?st?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- List/List.c | 114 ---------------------------------------------------- List/List.h | 25 ------------ List/test.c | 35 ---------------- 3 files changed, 174 deletions(-) delete mode 100644 List/List.c delete mode 100644 List/List.h delete mode 100644 List/test.c diff --git a/List/List.c b/List/List.c deleted file mode 100644 index cfce524..0000000 --- a/List/List.c +++ /dev/null @@ -1,114 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"List.h" -LTNode* LTBuyNode(LTDataType x) -{ - LTNode* node = (LTNode*)malloc(sizeof(LTNode)); - if (node == NULL) - { - perror("malloc fail!"); - exit(1); - } - node->Data=x; - node->prev = node->next = node; - return node; -} -LTNode* LTInit() -{ - LTNode* phead = LTBuyNode(-1); - return phead; -} - -void LTDestroy(LTNode* phead) -{ - LTNode* pcur = phead->next; - while (pcur != phead) - { - LTNode* next = pcur->next; - free(pcur); - pcur = next; - } - free(phead); - phead = NULL; -} -void LTPrint(LTNode* phead) -{ - LTNode* pcur = phead->next; - while (pcur != phead) - { - printf("%d->", pcur->Data); - pcur = pcur->next; - } - printf("\n"); -} -void LTPushBack(LTNode* phead, LTDataType x) -{ - assert(phead); - LTNode* ptail = phead->prev; - LTNode* node = LTBuyNode(x); - node->next = phead; - node->prev = ptail; - phead->prev = node; - ptail->next = node; -} -void LTPopBack(LTNode* phead) -{ - assert(phead && phead->next != phead); - LTNode* ptail = phead->prev; - ptail->prev->next = phead; - phead->prev = ptail->prev; - free(ptail); - ptail = NULL; -} -void LTPushFront(LTNode* phead, LTDataType x) -{ - assert(phead); - LTNode* node = LTBuyNode(x); - node->prev = phead; - node->next = phead->next; - phead->next = node; - node->next->prev = node; -} -void LTPopFront(LTNode* phead) -{ - assert(phead && phead->next != phead); - LTNode* del = phead->next; - del->next->prev = phead; - phead->next = del->next; - free(del); - del = NULL; -} -void LTInsert(LTNode* pos, LTDataType x) -{ - assert(pos); - - LTNode* newnode = LTBuyNode(x); - //pos newnode pos->next - newnode->next = pos->next; - newnode->prev = pos; - - pos->next->prev = newnode; - pos->next = newnode; -} -void LTErase(LTNode* pos) -{ - assert(pos); - //pos->prev pos pos->next - pos->next->prev = pos->prev; - pos->prev->next = pos->next; - - free(pos); - pos = NULL; -} -LTNode* LTFind(LTNode* phead, LTDataType x) -{ - LTNode* pcur = phead->next; - while (pcur != phead) - { - if (pcur->Data == x) - { - return pcur; - } - pcur = pcur->next; - } - return NULL; -} diff --git a/List/List.h b/List/List.h deleted file mode 100644 index 4a17291..0000000 --- a/List/List.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include -#include -#include - - -typedef int LTDataType; -typedef struct ListNode -{ - struct ListNode* prev; - struct ListNode* next; - LTDataType Data; -}LTNode; - -//void LTInit(LTNode** pphead); -LTNode* LTInit(); -void LTDestroy(LTNode* phead); -void LTPrint(LTNode* phead); -void LTPushBack(LTNode* phead, LTDataType x); -void LTPopBack(LTNode* phead); -void LTPushFront(LTNode* phead, LTDataType x); -void LTPopFront(LTNode* phead); -void LTInsert(LTNode* pos, LTDataType x); -void LTErase(LTNode* pos); -LTNode* LTFind(LTNode* phead, LTDataType x); \ No newline at end of file diff --git a/List/test.c b/List/test.c deleted file mode 100644 index 422170d..0000000 --- a/List/test.c +++ /dev/null @@ -1,35 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"List.h" - -void ListTest01() -{ - LTNode* lt = LTInit(); - - LTPushBack(lt, 2); - LTPrint(lt); - LTPushBack(lt, 3); - LTPrint(lt); - - LTPushFront(lt, 1); - LTPrint(lt); - LTPushFront(lt, 0); - LTPrint(lt); - - LTPopBack(lt); - LTPrint(lt); - LTPopBack(lt); - LTPrint(lt); - - LTPopFront(lt); - LTPrint(lt); - - LTDestroy(lt); - lt = NULL; - -} - -int main() -{ - ListTest01(); - return 0; -} \ No newline at end of file -- Gitee From 5de69ef57714ddc7a43bc65dd1098b912bf744d6 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:51:16 +0000 Subject: [PATCH 04/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Qu?= =?UTF-8?q?eue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Queue/Queue.c | 79 --------------------------------------------------- Queue/Queue.h | 28 ------------------ Queue/test.c | 48 ------------------------------- 3 files changed, 155 deletions(-) delete mode 100644 Queue/Queue.c delete mode 100644 Queue/Queue.h delete mode 100644 Queue/test.c diff --git a/Queue/Queue.c b/Queue/Queue.c deleted file mode 100644 index 7033172..0000000 --- a/Queue/Queue.c +++ /dev/null @@ -1,79 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"Queue.h" -void QueueInit(Queue* q) -{ - assert(q); - q->phead = q->ptail = NULL; - q->size = 0; -} -void QueuePush(Queue* q, QDataType x) -{ - assert(q); - QNode* newnode = (QNode*)malloc(sizeof(QNode)); - if (newnode == NULL) - { - perror("malloc failed"); - return; - } - if (q->phead == NULL) - { - q->phead = q->ptail = newnode; - } - else - { - q->ptail->next = newnode; - q->ptail = newnode; - } - newnode->next = NULL; - newnode->data = x; - q->size++; -} -void QueuePop(Queue* q) -{ - assert(q&&q->size>0); - if (q->phead->next == NULL)//һ¸ö½ڵã - { - free(q->phead); - q->phead = q->ptail = NULL; - } - else//¶à¸ö½ڵã - { - QNode* next = q->phead->next; - free(q->phead); - q->phead = next; - } - q->size--; -} -void QueueDestroy(Queue* q) -{ - assert(q); - QNode* pcur = q->phead; - while (pcur) - { - QNode* next = pcur->next; - free(pcur); - pcur = next; - } - q->phead=q->ptail=NULL; - q->size = 0; -} -QDataType QueueFront(Queue* q) -{ - assert(q && q->phead); - return q->phead->data; -} -QDataType QueueRear(Queue* q) -{ - assert(q && q->ptail); - return q->ptail->data; -} -bool QueueEmpty(Queue* q) -{ - assert(q); - return q->size == 0; -} -int QueueSize(Queue* q) -{ - assert(q); - return q->size; -} \ No newline at end of file diff --git a/Queue/Queue.h b/Queue/Queue.h deleted file mode 100644 index cc38ea5..0000000 --- a/Queue/Queue.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include -#include -#include -#include - -typedef int QDataType; -typedef struct QueueNode -{ - QDataType data; - struct QueueNode* next; -}QNode; - -typedef struct Queue -{ - QNode* phead; - QNode* ptail; - int size; -}Queue; - -void QueueInit(Queue* q); -void QueuePush(Queue* q,QDataType x); -void QueuePop(Queue* q); -void QueueDestroy(Queue* q); -QDataType QueueFront(Queue* q); -QDataType QueueRear(Queue* q); -bool QueueEmpty(Queue* q); -int QueueSize(Queue* q); diff --git a/Queue/test.c b/Queue/test.c deleted file mode 100644 index 91c54cf..0000000 --- a/Queue/test.c +++ /dev/null @@ -1,48 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"Stack.h" -#include"Queue.h" -void StackTest() -{ - Stack st; - STInit(&st); - STPush(&st, 1); - STPush(&st, 2); - STPush(&st, 3); - - while (!STEmpty(&st)) - { - printf("%d ", STTop(&st)); - STPop(&st); - } - STDestory(&st); -} - -void QueueTest() -{ - Queue q; - QueueInit(&q); - QueuePush(&q, 1); - QueuePush(&q, 2); - QueuePush(&q, 3); - printf("size=%d\n", QueueSize(&q)); - - while (!QueueEmpty(&q)) - { - printf("%d ",QueueFront(&q)); - QueuePop(&q); - } - - QueueDestroy(&q); - -} - -int main() -{ - -#if 0 - StackTest(); -#endif - - QueueTest(); - return 0; -} \ No newline at end of file -- Gitee From 8975c5d4ef4944c2e43650828af35ffeea73eed5 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:51:21 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20SL?= =?UTF-8?q?TNode/SLTNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SLTNode/SLTNode/SLTNode.c | 170 -------------------------------------- SLTNode/SLTNode/SLTNode.h | 24 ------ SLTNode/SLTNode/test.c | 40 --------- 3 files changed, 234 deletions(-) delete mode 100644 SLTNode/SLTNode/SLTNode.c delete mode 100644 SLTNode/SLTNode/SLTNode.h delete mode 100644 SLTNode/SLTNode/test.c diff --git a/SLTNode/SLTNode/SLTNode.c b/SLTNode/SLTNode/SLTNode.c deleted file mode 100644 index 9116a6d..0000000 --- a/SLTNode/SLTNode/SLTNode.c +++ /dev/null @@ -1,170 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"SLTNode.h" - -void SLTPrint(SLTNode* phead) -{ - SLTNode* pcur = phead; - while (pcur) - { - printf("%d->", pcur->data); - pcur = pcur->next; - } - printf("NULL"); - printf("\n"); -} - -SLTNode* SLTBuyNode(SLTDataType x) -{ - SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode)); - if (newnode == NULL) - { - perror("malloc failed!"); - exit(1); - } - newnode->data = x; - newnode->next = NULL; - return newnode; -} - -void SLTPushBack(SLTNode** pphead, SLTDataType x) -{ - assert(pphead); - SLTNode*newnode = SLTBuyNode(x); - if (*pphead==NULL) - { - *pphead = newnode; - } - else - { - SLTNode* ptail = *pphead; - while (ptail->next) - { - ptail = ptail->next; - } - ptail->next = newnode; - } - -} - -void SLTPushFront(SLTNode** pphead, SLTDataType x) -{ - assert(pphead); - SLTNode* newnode = SLTBuyNode(x); - newnode->next = *pphead; - *pphead = newnode; -} - -void SLTPopBack(SLTNode** pphead) -{ - assert(pphead&&*pphead); - if ((*pphead)->next == NULL) - { - free(*pphead); - *pphead = NULL; - } - else - { - SLTNode* pcur = *pphead; - SLTNode* ptail = *pphead; - while (ptail->next) - { - pcur = ptail; - ptail = ptail->next; - } - free(ptail); - ptail = NULL; - pcur->next = NULL; - } -} - -void SLTPopFront(SLTNode** pphead) -{ - assert(pphead && *pphead); - SLTNode* next = (*pphead)->next; - free(*pphead); - *pphead = next; -} - -SLTNode* SLTFind(SLTNode* phead, SLTDataType x) -{ - SLTNode* pcur = phead; - while (pcur) - { - if (pcur->data == x) - { - return pcur; - } - pcur = pcur->next; - } - return NULL; -} - -void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x) -{ - assert(pphead && pos&&*pphead); - if ((*pphead)->next == NULL) - { - SLTPushFront(*pphead, x); - } - else - { - SLTNode* pcur = *pphead; - while (pcur->next != pos) - { - pcur = pcur->next; - } - SLTNode* newnode = SLTBuyNode(x); - newnode->next = pos; - pcur->next = newnode; - } -} - -void SLTErase(SLTNode** pphead, SLTNode* pos) -{ - assert(pphead && pos && *pphead); - if ((*pphead)->next == NULL) - { - SLTPopFront(*pphead); - } - else - { - SLTNode* pcur = *pphead; - while (pcur->next!= pos) - { - pcur = pcur->next; - } - pcur->next = pos->next; - free(pos); - pos = NULL; - } -} - -void SLTInsertAfter(SLTNode* pos, SLTDataType x) -{ - assert(pos); - SLTNode* newnode = SLTBuyNode(x); - newnode->next = pos->next; - pos->next = newnode; -} - -void SLTEraseAfter(SLTNode* pos) -{ - assert(pos); - SLTNode* del= pos->next; - pos->next=del->next; - free(del); - del = NULL; -} - -void SListDesTroy(SLTNode** pphead) -{ - assert(pphead&&*pphead); - SLTNode* pcur = *pphead; - while (pcur) - { - SLTNode* next = pcur->next; - free(pcur); - pcur = next; - } - *pphead = NULL; -} \ No newline at end of file diff --git a/SLTNode/SLTNode/SLTNode.h b/SLTNode/SLTNode/SLTNode.h deleted file mode 100644 index d8822cc..0000000 --- a/SLTNode/SLTNode/SLTNode.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include -#include -#include - -typedef int SLTDataType; -typedef struct SLTNodelist -{ - SLTDataType data; - struct SLTNodelist* next; -}SLTNode; - -void SLTPrint(SLTNode* p); -void SLTPushBack(SLTNode** pphead, SLTDataType x); -void SLTPushFront(SLTNode** pphead, SLTDataType x); -void SLTPopBack(SLTNode** pphead); -void SLTPopFront(SLTNode** pphead); -SLTNode* SLTBuyNode(SLTDataType x); -SLTNode* SLTFind(SLTNode* phead, SLTDataType x); -void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x);//½ڵã֮ǰ²åÈëÊý¾Ý -void SLTErase(SLTNode** pphead, SLTNode* pos);//ɾ³ý½ڵã -void SLTInsertAfter(SLTNode* pos, SLTDataType x);//½ڵã֮ºó²åÈëÊý¾Ý -void SLTEraseAfter(SLTNode* pos);//ɾ³ý½ڵã֮ºóÊý¾Ý -void SListDesTroy(SLTNode** pphead); \ No newline at end of file diff --git a/SLTNode/SLTNode/test.c b/SLTNode/SLTNode/test.c deleted file mode 100644 index ba875ea..0000000 --- a/SLTNode/SLTNode/test.c +++ /dev/null @@ -1,40 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"SLTNode.h" - -void test01() -{ - SLTNode* SLT=NULL; - SLTPushBack(&SLT, 1); - SLTPrint(SLT); - SLTPushBack(&SLT, 2); - SLTPrint(SLT); - SLTPushBack(&SLT, 3); - SLTPrint(SLT); - - SLTPushFront(&SLT, 0); - SLTPrint(SLT);//0 1 2 3 - - SLTInsert(&SLT, SLTFind(SLT,2), 3); - SLTPrint(SLT);// 0 1 3 2 3 - - SLTErase(&SLT, SLTFind(SLT, 3)); - SLTPrint(SLT); - - SListDesTroy(&SLT); - SLTPrint(SLT); - /*SLTPopFront(&SLT); - SLTPrint(SLT); - SLTPopFront(&SLT); - SLTPrint(SLT); - SLTPopFront(&SLT); - SLTPrint(SLT); - SLTPopFront(&SLT); - SLTPrint(SLT);*/ - -} - -int main() -{ - test01(); - return 0; -} \ No newline at end of file -- Gitee From ed02cd5a8c7fa9427dfa75f4566b4af9e7467322 Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:51:36 +0000 Subject: [PATCH 06/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20St?= =?UTF-8?q?ack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stack/Stack.c | 56 --------------------------------------------------- Stack/Stack.h | 21 ------------------- Stack/test.c | 48 ------------------------------------------- 3 files changed, 125 deletions(-) delete mode 100644 Stack/Stack.c delete mode 100644 Stack/Stack.h delete mode 100644 Stack/test.c diff --git a/Stack/Stack.c b/Stack/Stack.c deleted file mode 100644 index 422ed7b..0000000 --- a/Stack/Stack.c +++ /dev/null @@ -1,56 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"Stack.h" - -void STInit(Stack* ps) -{ - assert(ps); - ps->a = NULL; - ps->top = ps->capacity = 0; -} -void STPush(Stack* ps,STDataType x) -{ - assert(ps); - if (ps->capacity == ps->top) - { - int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2; - STDataType* tmp = (STDataType*)realloc(ps->a, newcapacity * sizeof(STDataType)); - if (tmp == NULL) - { - perror("realloc failed"); - return; - } - ps->a = tmp; - ps->capacity = newcapacity; - } - ps->a[ps->top++] = x; -} -void STPop(Stack* ps) -{ - assert(ps&&ps->top!=0); - ps->top--; -} -STDataType STTop(Stack* ps) -{ - assert(ps&&ps->top>0); - - return ps->a[ps->top - 1]; -} -int STSize(Stack* ps) -{ - assert(ps); - return ps->top; -} - -void STDestory(Stack* ps) -{ - assert(ps); - free(ps->a); - ps->a = NULL; - ps->top = ps->capacity = 0; -} -bool STEmpty(Stack* ps) -{ - assert(ps); - - return ps->top == 0; -} \ No newline at end of file diff --git a/Stack/Stack.h b/Stack/Stack.h deleted file mode 100644 index 50d9394..0000000 --- a/Stack/Stack.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include -#include -#include -#include - -typedef int STDataType; -typedef struct Stack -{ - STDataType* a; - int top; - int capacity; -}Stack; - -void STInit(Stack* ps); -void STPush(Stack* ps, STDataType x); -void STPop(Stack* ps); -STDataType STTop(Stack* ps); -int STSize(Stack* ps); -void STDestory(Stack* ps); -bool STEmpty(Stack* ps); \ No newline at end of file diff --git a/Stack/test.c b/Stack/test.c deleted file mode 100644 index 91c54cf..0000000 --- a/Stack/test.c +++ /dev/null @@ -1,48 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"Stack.h" -#include"Queue.h" -void StackTest() -{ - Stack st; - STInit(&st); - STPush(&st, 1); - STPush(&st, 2); - STPush(&st, 3); - - while (!STEmpty(&st)) - { - printf("%d ", STTop(&st)); - STPop(&st); - } - STDestory(&st); -} - -void QueueTest() -{ - Queue q; - QueueInit(&q); - QueuePush(&q, 1); - QueuePush(&q, 2); - QueuePush(&q, 3); - printf("size=%d\n", QueueSize(&q)); - - while (!QueueEmpty(&q)) - { - printf("%d ",QueueFront(&q)); - QueuePop(&q); - } - - QueueDestroy(&q); - -} - -int main() -{ - -#if 0 - StackTest(); -#endif - - QueueTest(); - return 0; -} \ No newline at end of file -- Gitee From 4b6841ee67f98e1d1627a083d9f4a79eda5550ca Mon Sep 17 00:00:00 2001 From: LUHAN <3041492091@qq.com> Date: Tue, 10 Feb 2026 07:51:43 +0000 Subject: [PATCH 07/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20se?= =?UTF-8?q?qlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seqlist/seqlist.c | 112 ---------------------------------------------- seqlist/seqlist.h | 20 --------- seqlist/test.c | 51 --------------------- 3 files changed, 183 deletions(-) delete mode 100644 seqlist/seqlist.c delete mode 100644 seqlist/seqlist.h delete mode 100644 seqlist/test.c diff --git a/seqlist/seqlist.c b/seqlist/seqlist.c deleted file mode 100644 index 6eabb61..0000000 --- a/seqlist/seqlist.c +++ /dev/null @@ -1,112 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"seqlist.h" -void SeqListInit(SL* ps) -{ - ps->arr = NULL; - ps->size = ps->capacity = 0; -} -void SeqListDesTroy(SL* ps) -{ - if (ps->arr) - { - free(ps->arr); - } - ps->arr = NULL; - ps->size = ps->capacity = 0; -} -void SeqListPrint(SL sl) -{ - for (int i = 0; i < sl.size; i++) - { - printf("%d ", sl.arr[i]); - } - printf("\n"); -} - -void CheckCapacity(SL* ps) //2±¶À©ÈÝ -{ - assert(ps); - int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity; - if (ps->size == ps->capacity) - { - SLDATATYPE* tmp = (SLDATATYPE*)realloc(ps->arr, newcapacity * sizeof(SLDATATYPE)); - if (tmp == NULL) - { - perror("realloc fail!"); - exit(1); - } - ps->arr = tmp; - ps->capacity = newcapacity; - } - -} -void SLPushBack(SL* ps, SLDATATYPE x) -{ - assert(ps); - CheckCapacity(ps); - ps->arr[ps->size++] = x; -} -void SLPopBack(SL* ps) -{ - assert(ps); - assert(ps->size); - ps->size--; -} - -void SLPushFront(SL* ps, SLDATATYPE x) -{ - assert(ps); - CheckCapacity(ps); - for (int i = ps->size; i > 0; i--) - { - ps->arr[i] = ps->arr[i-1]; - } - ps->arr[0] = x; - ps->size++; -} - -void SLPopFront(SL* ps) -{ - assert(ps); - assert(ps->size); - for (int i = 0; i size-1; i++) - { - ps->arr[i] = ps->arr[i+1];//arr[size-2]=arr[size-1] - } - ps->size--; -} - -void SLInsert(SL* ps, int pos, SLDATATYPE x) -{ - assert(ps); - assert(pos >= 0 && pos < ps->size); - CheckCapacity(ps); - for (int i = ps->size; i > pos; i--) - { - ps->arr[i] = ps->arr[i - 1];//arr[pos+1]=arr[pos] - } - ps->arr[pos] = x; - ps->size++; -} - -void SLErase(SL* ps, int pos) -{ - assert(ps); - assert(pos >= 0 && pos < ps->size); - for (int i = pos; i size-1; i++) - { - ps->arr[i] = ps->arr[i+1];//arr[pos]=arr[pos+1],arr[size-2]=arr[size-1] - } - ps->size--; -} - -int SLFind(SL* ps, SLDATATYPE x) -{ - assert(ps); - for (int i = 0; i < ps->size; i++) - { - if (ps->arr[i] == x) - return i; - } - return -1; -} \ No newline at end of file diff --git a/seqlist/seqlist.h b/seqlist/seqlist.h deleted file mode 100644 index b3428ec..0000000 --- a/seqlist/seqlist.h +++ /dev/null @@ -1,20 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include -#include -#include -typedef int SLDATATYPE; -typedef struct SeqList -{ - SLDATATYPE* arr; - int size; - int capacity; -}SL; - -void SeqListInit(SL* ps); -void SeqListDesTroy(SL* ps); -void SeqListPrint(SL sl); -void CheckCapacity(SL* ps); -void SLPushBack(SL* ps, SLDATATYPE x); -void SLPopBack(SL* ps); -void SLPushFront(SL* ps, SLDATATYPE x); -void SLPopFront(SL* ps); \ No newline at end of file diff --git a/seqlist/test.c b/seqlist/test.c deleted file mode 100644 index d9276b1..0000000 --- a/seqlist/test.c +++ /dev/null @@ -1,51 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include"seqlist.h" - -void test() -{ - SL sl; - SeqListInit(&sl); - - SLPushBack(&sl, 1); - SLPushBack(&sl, 2); - SLPushBack(&sl, 3); - SLPushFront(&sl, 0); - SLPushFront(&sl, -1); - SeqListPrint(sl);//-1 0 1 2 3 - - SLPopBack(&sl); - SeqListPrint(sl);//-1 0 1 2 - /*SLPopBack(&sl); - SeqListPrint(sl); - SLPopBack(&sl); - SeqListPrint(sl); - SLPopBack(&sl); - SeqListPrint(sl); - SLPopBack(&sl); - SeqListPrint(sl); - SLPopBack(&sl); - SeqListPrint(sl);*/ - - SLPopFront(&sl); - SeqListPrint(sl); - /*SLPopFront(&sl); - SeqListPrint(sl); - SLPopFront(&sl); - SeqListPrint(sl); - SLPopFront(&sl); - SeqListPrint(sl); - SLPopFront(&sl); - SeqListPrint(sl);*/ - - SeqListDesTroy(&sl); - - -} - - -int main() -{ - - test(); - return 0; -} \ No newline at end of file -- Gitee From 7780aa612a9d651ea0f900362edde1d8a49017bc Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 08:32:53 +0000 Subject: [PATCH 08/14] =?UTF-8?q?=E7=8E=AF=E5=BD=A2=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E6=89=BE=E5=88=B0=E7=8E=AF=E7=9A=84=E5=BC=80=E5=A7=8B=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- OJ-circlelist2 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 OJ-circlelist2 diff --git a/OJ-circlelist2 b/OJ-circlelist2 new file mode 100644 index 0000000..2d2416b --- /dev/null +++ b/OJ-circlelist2 @@ -0,0 +1,29 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode *detectCycle(struct ListNode *head) +{ + struct ListNode *fast=head,*slow=head,*meet; + while(fast&&fast->next) + { + +fast=fast->next->next; +slow=slow->next; + +if(fast==slow) +{ +meet=slow; +while(head!=meet) +{ + head=head->next; + meet=meet->next; +} +return meet; +} + } + return NULL; +} \ No newline at end of file -- Gitee From 90d6bfd9804cf6092c61a37f2847590574e23b64 Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 09:00:40 +0000 Subject: [PATCH 09/14] =?UTF-8?q?=E5=88=A9=E7=94=A8=E6=A0=88=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=8B=AC=E5=8F=B7=E6=98=AF=E5=90=A6=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- OJ-Stack1 | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 OJ-Stack1 diff --git a/OJ-Stack1 b/OJ-Stack1 new file mode 100644 index 0000000..1610d35 --- /dev/null +++ b/OJ-Stack1 @@ -0,0 +1,96 @@ +typedef char STDataType; +typedef struct Stack +{ + STDataType* a; + int top; + int capacity; +}Stack; + + +void STInit(Stack* ps) +{ + assert(ps); + ps->a = NULL; + ps->top = ps->capacity = 0; +} +void STPush(Stack* ps,STDataType x) +{ + assert(ps); + if (ps->capacity == ps->top) + { + int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2; + STDataType* tmp = (STDataType*)realloc(ps->a, newcapacity * sizeof(STDataType)); + if (tmp == NULL) + { + perror("realloc failed"); + return; + } + ps->a = tmp; + ps->capacity = newcapacity; + } + ps->a[ps->top++] = x; +} +void STPop(Stack* ps) +{ + assert(ps&&ps->top!=0); + ps->top--; +} +STDataType STTop(Stack* ps) +{ + assert(ps&&ps->top>0); + + return ps->a[ps->top - 1]; +} +int STSize(Stack* ps) +{ + assert(ps); + return ps->top; +} + +void STDestory(Stack* ps) +{ + assert(ps); + free(ps->a); + ps->a = NULL; + ps->top = ps->capacity = 0; +} +bool STEmpty(Stack* ps) +{ + assert(ps); + + return ps->top == 0; +} + + + + +bool isValid(char* s) +{ + Stack st; + STInit(&st); + while(*s) + { + if(*s=='('||*s=='['||*s=='{') + { + STPush(&st,*s); + } + else + { + if(STEmpty(&st)) + { + return false; + } + char top=STTop(&st); + STPop(&st); + +if((*s==')'&&top!='(')||(*s=='}'&&top!='{')||(*s==']'&&top!='[')) +{ +return false; +} + } + + s++; + } + + return STEmpty(&st); +} \ No newline at end of file -- Gitee From aba3bd916cb58a0bdd1dc1eac7eb3159bfab526f Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 10:43:45 +0000 Subject: [PATCH 10/14] =?UTF-8?q?=E7=94=A8=E9=98=9F=E5=88=97=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=A0=88.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- ...0\227\345\256\236\347\216\260\346\240\210" | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 "\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" diff --git "a/\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" "b/\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" new file mode 100644 index 0000000..168ef25 --- /dev/null +++ "b/\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" @@ -0,0 +1,168 @@ +typedef int QDataType; +typedef struct QueueNode +{ + QDataType data; + struct QueueNode* next; +}QNode; + +typedef struct Queue +{ + QNode* phead; + QNode* ptail; + int size; +}Queue; + +void QueueInit(Queue* q) +{ + assert(q); + q->phead = q->ptail = NULL; + q->size = 0; +} +void QueuePush(Queue* q, QDataType x) +{ + assert(q); + QNode* newnode = (QNode*)malloc(sizeof(QNode)); + if (newnode == NULL) + { + perror("malloc failed"); + return; + } + if (q->phead == NULL) + { + q->phead = q->ptail = newnode; + } + else + { + q->ptail->next = newnode; + q->ptail = newnode; + } + newnode->next = NULL; + newnode->data = x; + q->size++; +} +void QueuePop(Queue* q) +{ + assert(q&&q->size>0); + if (q->phead->next == NULL)//一个节点 + { + free(q->phead); + q->phead = q->ptail = NULL; + } + else//多个节点 + { + QNode* next = q->phead->next; + free(q->phead); + q->phead = next; + } + q->size--; +} +void QueueDestroy(Queue* q) +{ + assert(q); + QNode* pcur = q->phead; + while (pcur) + { + QNode* next = pcur->next; + free(pcur); + pcur = next; + } + q->phead=q->ptail=NULL; + q->size = 0; +} +QDataType QueueFront(Queue* q) +{ + assert(q && q->phead); + return q->phead->data; +} +QDataType QueueRear(Queue* q) +{ + assert(q && q->ptail); + return q->ptail->data; +} +bool QueueEmpty(Queue* q) +{ + assert(q); + return q->size == 0; +} +int QueueSize(Queue* q) +{ + assert(q); + return q->size; +} + + +typedef struct +{ + //只是两个指针,需要为他们单独开辟内存,如果是直接创建queue的变量则不用,不过不方便使用 + Queue* q1; + Queue* q2; +} MyStack; + + +MyStack* myStackCreate() { + MyStack* ps=(MyStack*)malloc(sizeof(MyStack)); + ps->q1 = (Queue*)malloc(sizeof(Queue)); // 分配内存 + ps->q2 = (Queue*)malloc(sizeof(Queue)); + QueueInit(ps->q1); + QueueInit(ps->q2); + return ps; +} + +void myStackPush(MyStack* obj, int x) +{ + assert(obj); + if(QueueEmpty(obj->q1)&&QueueEmpty(obj->q2)) + { + QueuePush(obj->q1,x); + } + else + { + Queue* valid=QueueEmpty(obj->q1)?obj->q2:obj->q1; + QueuePush(valid,x); + } +} + +int myStackPop(MyStack* obj) +{ +assert(obj&&!(QueueEmpty(obj->q1)&&QueueEmpty(obj->q2))); +Queue* valid=obj->q1; +Queue* empty=obj->q2; +if(QueueEmpty(obj->q1)) +{ + valid=obj->q2; + empty=obj->q1; +} + +while(valid->size>1) +{ +QueuePush(empty,QueueFront(valid)); +QueuePop(valid); +} + +int ret=QueueFront(valid); +QueuePop(valid); + +return ret; +} + +int myStackTop(MyStack* obj) +{ + assert(obj); + Queue* valid=QueueEmpty(obj->q1)?obj->q2:obj->q1; + return QueueRear(valid); +} + +bool myStackEmpty(MyStack* obj) +{ + assert(obj); + return QueueEmpty(obj->q1)&&QueueEmpty(obj->q2); +} + +void myStackFree(MyStack* obj) +{ + assert(obj); + QueueDestroy(obj->q1); + QueueDestroy(obj->q2); + free(obj); +} + -- Gitee From b865019803ffda1395ae3802282a4ca3fb32a5ff Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 10:44:26 +0000 Subject: [PATCH 11/14] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E7=94=A8?= =?UTF-8?q?=E9=98=9F=E5=88=97=E5=AE=9E=E7=8E=B0=E6=A0=88=20=E4=B8=BA=20OJ-?= =?UTF-8?q?Queue1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\345\210\227\345\256\236\347\216\260\346\240\210" => OJ-Queue1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" => OJ-Queue1 (100%) diff --git "a/\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" b/OJ-Queue1 similarity index 100% rename from "\347\224\250\351\230\237\345\210\227\345\256\236\347\216\260\346\240\210" rename to OJ-Queue1 -- Gitee From 445fe4d0db7e5f8daa992da006e5b98a4dc20316 Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 12:00:40 +0000 Subject: [PATCH 12/14] =?UTF-8?q?=E7=94=A8=E6=A0=88=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- OJ-Stack2 | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 OJ-Stack2 diff --git a/OJ-Stack2 b/OJ-Stack2 new file mode 100644 index 0000000..206d5df --- /dev/null +++ b/OJ-Stack2 @@ -0,0 +1,150 @@ +typedef int STDataType; +typedef struct Stack +{ + STDataType* a; + int top; + int capacity; +}Stack; + +void STInit(Stack* ps) +{ + assert(ps); + ps->a = NULL; + ps->top = ps->capacity = 0; +} +void STPush(Stack* ps,STDataType x) +{ + assert(ps); + if (ps->capacity == ps->top) + { + int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2; + STDataType* tmp = (STDataType*)realloc(ps->a, newcapacity * sizeof(STDataType)); + if (tmp == NULL) + { + perror("realloc failed"); + return; + } + ps->a = tmp; + ps->capacity = newcapacity; + } + ps->a[ps->top++] = x; +} +void STPop(Stack* ps) +{ + assert(ps&&ps->top!=0); + ps->top--; +} +STDataType STTop(Stack* ps) +{ + assert(ps&&ps->top>0); + + return ps->a[ps->top - 1]; +} +int STSize(Stack* ps) +{ + assert(ps); + return ps->top; +} + +void STDestory(Stack* ps) +{ + assert(ps); + free(ps->a); + ps->a = NULL; + ps->top = ps->capacity = 0; +} +bool STEmpty(Stack* ps) +{ + assert(ps); + + return ps->top == 0; +} + + +typedef struct +{ + Stack* ps1; + Stack* ps2; +} MyQueue; + + +MyQueue* myQueueCreate() +{ + MyQueue* ret=(MyQueue*)malloc(sizeof(MyQueue)); + ret->ps1=(Stack*)malloc(sizeof(Stack)); + ret->ps2=(Stack*)malloc(sizeof(Stack)); + STInit(ret->ps1); + STInit(ret->ps2); + + return ret; +} + +void myQueuePush(MyQueue* obj, int x) +{ +assert(obj); +if(STEmpty(obj->ps1)&&STEmpty(obj->ps2)) +{ +STPush(obj->ps1,x); +} +else +{ + Stack* nonempty=STEmpty(obj->ps1)?obj->ps2:obj->ps1; + STPush(nonempty,x); +} + +} + +int myQueuePop(MyQueue* obj) +{ + assert(obj&&!(STEmpty(obj->ps1)&&STEmpty(obj->ps2))); +Stack* nonempty=obj->ps1; +Stack* empty=obj->ps2; +if(STEmpty(obj->ps1)) +{ + nonempty=obj->ps2; + empty=obj->ps1; +} + +while(STSize(nonempty)>1) +{ + STPush(empty,STTop(nonempty)); + STPop(nonempty); +} + +int ret=STTop(nonempty); +STPop(nonempty); + +//区别于队列实现栈,由于栈一端进一端出会颠倒方向,所以拿出队头后还得重新倒回去 +//所以两个栈有一个是固定空,一个是固定存的,之前的假设逻辑可以一开始就确认好 +while(STSize(empty)) +{ + STPush(nonempty,STTop(empty)); + STPop(empty); +} + +return ret; +} + +int myQueuePeek(MyQueue* obj) +{ + assert(obj); + Stack* nonempty=STEmpty(obj->ps1)?obj->ps2:obj->ps1; + + return nonempty->a[0]; +} + +bool myQueueEmpty(MyQueue* obj) +{ +assert(obj); + +return STEmpty(obj->ps1)&&STEmpty(obj->ps2); +} + +void myQueueFree(MyQueue* obj) +{ + assert(obj); + STDestory(obj->ps1); + STDestory(obj->ps2); + + free(obj); +} -- Gitee From 1ec2d5ac2a75432a7b4744d3a7d1dd2018a33035 Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Tue, 10 Feb 2026 15:04:17 +0000 Subject: [PATCH 13/14] =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E9=98=9F=E5=88=97=20?= =?UTF-8?q?=E5=88=A9=E7=94=A8=E6=95=B0=E7=BB=84=E4=B8=8B=E6=A0=87=E6=A8=A1?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E8=BF=9B=E8=A1=8C=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- OJ-queue | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 OJ-queue diff --git a/OJ-queue b/OJ-queue new file mode 100644 index 0000000..a6fd6f5 --- /dev/null +++ b/OJ-queue @@ -0,0 +1,81 @@ +typedef struct { + int* a; + int head; + int tail; + int k; +} MyCircularQueue; + + +MyCircularQueue* myCircularQueueCreate(int k) +{ +MyCircularQueue* ret=(MyCircularQueue*)malloc(sizeof(MyCircularQueue)); +ret->a=(int*)malloc((k+1)*sizeof(int)); +ret->k=k; +ret->head=ret->tail=0; +return ret; +} +bool myCircularQueueIsEmpty(MyCircularQueue* obj) +{ +return obj->head==obj->tail; +} + +bool myCircularQueueIsFull(MyCircularQueue* obj) +{ +return (obj->tail+1)%(obj->k+1)==obj->head; +} + + +bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) +{ +if(myCircularQueueIsFull(obj)) +{ + return false; +} +else{ + obj->a[obj->tail]=value; + ++obj->tail; + obj->tail%=(obj->k+1); + //tail指向队尾的下个位置 + return true; +} + + +} + +bool myCircularQueueDeQueue(MyCircularQueue* obj) +{ + if(myCircularQueueIsEmpty(obj)) + return false; + +++obj->head; +obj->head%=(obj->k+1); +return true; + +} + +int myCircularQueueFront(MyCircularQueue* obj) +{ + if(myCircularQueueIsEmpty(obj)) + return -1; + else + return obj->a[obj->head]; + +} + +int myCircularQueueRear(MyCircularQueue* obj) +{ + if(myCircularQueueIsEmpty(obj)) + return -1; + + else + return obj->a[(obj->tail-1+obj->k+1)%(obj->k+1)]; + //加k+1对正数模运算没影 响,但可以让负数变正数 + //也可以用三目运算符对tail等于0的情况单独赋值 +} + +void myCircularQueueFree(MyCircularQueue* obj) +{ + assert(obj); + free(obj->a); + free(obj); +} \ No newline at end of file -- Gitee From 5bdedfb601f21b717a9ac706be17fd23ea371b65 Mon Sep 17 00:00:00 2001 From: Mercury <3041492091@qq.com> Date: Sat, 14 Feb 2026 18:25:39 +0000 Subject: [PATCH 14/14] =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E5=85=A5?= =?UTF-8?q?=E9=97=A8=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mercury <3041492091@qq.com> --- OJ-BinaryTreeSimple | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 OJ-BinaryTreeSimple diff --git a/OJ-BinaryTreeSimple b/OJ-BinaryTreeSimple new file mode 100644 index 0000000..f6d46af --- /dev/null +++ b/OJ-BinaryTreeSimple @@ -0,0 +1,54 @@ +bool isSameTree(struct TreeNode* p, struct TreeNode* q)//相同二叉树 +{ +if(p==NULL&&q==NULL) + return true; +if(p==NULL||q==NULL) +return false; + +if(p->val!=q->val) +return false; + +return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right); +} + +bool isUnivalTree(struct TreeNode* root) //单值二叉树 +{ + if(root==NULL) + return true; + if((root->left&&root->left->val!=root->val) + ||(root->right&&root->right->val!=root->val)) + return false; + return isUnivalTree(root->left)&&isUnivalTree(root->right); +} + +bool _isSymmetric(struct TreeNode* q,struct TreeNode* p) //对称二叉树的判断 +{ + if(q==NULL&&p==NULL) + return true; + if(q==NULL||p==NULL) + return false; + if(q->val!=p->val) + return false; + +return _isSymmetric(q->left,p->right)&&_isSymmetric(q->right,p->left); +} + +bool isSymmetric(struct TreeNode* root) +{ + return _isSymmetric(root->left,root->right); +} + +bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) +{ + +if(root==NULL) +return false; + +if(isSameTree(root,subRoot)) +return true; + +return isSubtree(root->left,subRoot)||isSubtree(root->right,subRoot); + +} + + -- Gitee