feat(*): 代码仓库初始化
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.venv
|
||||||
17
DataStructure/README.md
Normal file
17
DataStructure/README.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## 数据结构
|
||||||
|
|
||||||
|
### 文件介绍
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── test1 # 实验1
|
||||||
|
├── test2 # 实验2
|
||||||
|
└── test3 # 实验3
|
||||||
|
```
|
||||||
229
DataStructure/test1/实验一.cpp
Normal file
229
DataStructure/test1/实验一.cpp
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef struct LNode
|
||||||
|
{
|
||||||
|
int data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
struct LNode *next; // ָ<><D6B8><EFBFBD><EFBFBD>
|
||||||
|
} LNode, *LinkList; // LinkListΪָ<CEAA><D6B8>LNode<64><65><EFBFBD>͵<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
void chushihua(LinkList &L, LinkList &M, LinkList &N, LinkList &H) // <20><>ʼ<EFBFBD><CABC><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>L<EFBFBD><4C>M<EFBFBD><4D>N<EFBFBD><4E>H
|
||||||
|
{
|
||||||
|
// todo list
|
||||||
|
L = (LinkList)malloc(sizeof(LNode));
|
||||||
|
M = (LinkList)malloc(sizeof(LNode));
|
||||||
|
N = (LinkList)malloc(sizeof(LNode));
|
||||||
|
H = (LinkList)malloc(sizeof(LNode));
|
||||||
|
L->next = NULL; // ֱ<><D6B1><EFBFBD>ÿգ<C3BF><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||||
|
M->next = NULL;
|
||||||
|
N->next = NULL;
|
||||||
|
H->next = NULL;
|
||||||
|
}
|
||||||
|
void Emp(LinkList &L) // <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>L<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD>ձ<EFBFBD>
|
||||||
|
{
|
||||||
|
// if (//todo list)
|
||||||
|
if (L->next == NULL)
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD>\n");
|
||||||
|
else
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ǿձ<EFBFBD><EFBFBD><EFBFBD>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Length(LinkList L)
|
||||||
|
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
|
||||||
|
LNode *p; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>p
|
||||||
|
p = L->next; // pָ<70><D6B8><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>(<28><>Ԫ<EFBFBD><D4AA><EFBFBD>)
|
||||||
|
int length = 0;
|
||||||
|
// todo list //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ͳ<>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||||
|
while (p != NULL)
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\n", length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
|
||||||
|
void xianshi(LinkList &L)
|
||||||
|
{
|
||||||
|
LNode *p; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>p //LinkList p;
|
||||||
|
p = L;
|
||||||
|
while (p->next != NULL)
|
||||||
|
{
|
||||||
|
printf("%4d", p->next->data);
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
printf("\n"); // <20><><EFBFBD>ӻ<EFBFBD><D3BB>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ڲ鿴
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>L<EFBFBD>в<EFBFBD><D0B2><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||||
|
void charu_1(LinkList &L, int n)
|
||||||
|
{
|
||||||
|
LNode *q, *p;
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
{
|
||||||
|
p = L; // <20><>ÿ<EFBFBD><C3BF>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD>pָ<70><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ڵ<EFBFBD>L
|
||||||
|
q = (LinkList)malloc(sizeof(LNode)); // Ϊ<>µĽڵ<C4BD><DAB5><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD><EFBFBD>qָ<71><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ", i);
|
||||||
|
scanf("%d", &q->data); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>洢<EFBFBD><E6B4A2>qָ<71><D6B8>Ľڵ<C4BD><DAB5>data<74>ֶ<EFBFBD><D6B6><EFBFBD>
|
||||||
|
q->next = NULL; // <20><><EFBFBD>½ڵ<C2BD><DAB5>nextָ<74><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪNULL<4C><4C><EFBFBD><EFBFBD>ʾ<EFBFBD>½ڵ㵱ǰ<E3B5B1><C7B0>ָ<EFBFBD><D6B8><EFBFBD>κνڵ㡣
|
||||||
|
|
||||||
|
// <20><><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>λ<EFBFBD><CEBB>
|
||||||
|
while (p->next != NULL && p->next->data < q->data)
|
||||||
|
{
|
||||||
|
p = p->next; // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
|
||||||
|
}
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>½ڵ<C2BD>
|
||||||
|
q->next = p->next;
|
||||||
|
p->next = q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2<><32><EFBFBD>ֽ⣺<D6BD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>L<EFBFBD>е<EFBFBD>Ԫ<EFBFBD>ط<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>M<EFBFBD><4D>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ǡ<EFBFBD>
|
||||||
|
void fenbiao(LinkList &L, LinkList &M, LinkList &N)
|
||||||
|
{
|
||||||
|
LNode *j, *o, *p, *temp;
|
||||||
|
p = L;
|
||||||
|
while (p->next != NULL)
|
||||||
|
{
|
||||||
|
temp = p->next; // <20><><EFBFBD>浱ǰ<E6B5B1>ڵ<EFBFBD>
|
||||||
|
p->next = temp->next; // <20><>ǰ<EFBFBD>ƶ<EFBFBD>p<EFBFBD><70>next<78><74><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
if (temp->data % 2 == 0) // ż<><C5BC>Ԫ<EFBFBD>أ<EFBFBD>ǰ<EFBFBD>巨<EFBFBD><E5B7A8>M
|
||||||
|
{
|
||||||
|
o = (LinkList)malloc(sizeof(LNode));
|
||||||
|
o->data = temp->data;
|
||||||
|
o->next = M->next;
|
||||||
|
M->next = o;
|
||||||
|
}
|
||||||
|
else // <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>ǰ<EFBFBD>巨<EFBFBD><E5B7A8>N
|
||||||
|
{
|
||||||
|
j = (LinkList)malloc(sizeof(LNode));
|
||||||
|
j->data = temp->data;
|
||||||
|
j->next = N->next;
|
||||||
|
N->next = j;
|
||||||
|
}
|
||||||
|
free(temp); // <20>ͷ<EFBFBD>ԭ<EFBFBD>ڵ<EFBFBD><DAB5>ڴ<EFBFBD>
|
||||||
|
}
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD>Ϊ:");
|
||||||
|
xianshi(N); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>N<EFBFBD><4E>
|
||||||
|
printf("ż<EFBFBD><EFBFBD>Ϊ:");
|
||||||
|
xianshi(M); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ż<EFBFBD><C5BC>Ӧ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>M<EFBFBD><4D>
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3<><33><EFBFBD>ϲ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>J<EFBFBD><4A>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>ϲ<EFBFBD>Ϊһ<CEAA><D2BB><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>H<EFBFBD><48><EFBFBD>ϲ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ԫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԡ<EFBFBD>
|
||||||
|
void hebiao(LinkList &J, LinkList &O, LinkList &H)
|
||||||
|
{
|
||||||
|
LNode *p, *q, *t, *m;
|
||||||
|
p = J->next; // ָ<><D6B8><EFBFBD><EFBFBD>Ԫ<EFBFBD>ڵ<EFBFBD>
|
||||||
|
q = O->next;
|
||||||
|
m = H; // m<>൱<EFBFBD><E0B5B1>βָ<CEB2>룬<EFBFBD><EBA3AC>ʼָ<CABC><D6B8>ͷ<EFBFBD>ڵ<EFBFBD>
|
||||||
|
|
||||||
|
// <20><><EFBFBD>Hԭ<48><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
H->next = NULL;
|
||||||
|
|
||||||
|
while (p != NULL && q != NULL) // <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>
|
||||||
|
{
|
||||||
|
if (p->data > q->data) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
{
|
||||||
|
t = (LinkList)malloc(sizeof(LNode));
|
||||||
|
t->data = p->data;
|
||||||
|
t->next = NULL;
|
||||||
|
m->next = t; // β<><CEB2>
|
||||||
|
m = t; // <20><><EFBFBD><EFBFBD>βָ<CEB2><D6B8>
|
||||||
|
p = p->next; // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||||
|
}
|
||||||
|
else // ȡż<C8A1><C5BC>
|
||||||
|
{
|
||||||
|
t = (LinkList)malloc(sizeof(LNode));
|
||||||
|
t->data = q->data;
|
||||||
|
t->next = NULL;
|
||||||
|
m->next = t; // β<><CEB2>
|
||||||
|
m = t; // <20><><EFBFBD><EFBFBD>βָ<CEB2><D6B8>
|
||||||
|
q = q->next; // <20>ƶ<EFBFBD>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>루<EFBFBD><EBA3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>p<EFBFBD><70>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
||||||
|
while (p != NULL)
|
||||||
|
{
|
||||||
|
t = (LinkList)malloc(sizeof(LNode));
|
||||||
|
t->data = p->data;
|
||||||
|
t->next = NULL;
|
||||||
|
m->next = t;
|
||||||
|
m = t;
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ż<EFBFBD><C5BC><EFBFBD>ڵ<EFBFBD>
|
||||||
|
while (q != NULL)
|
||||||
|
{
|
||||||
|
t = (LinkList)malloc(sizeof(LNode));
|
||||||
|
t->data = q->data;
|
||||||
|
t->next = NULL;
|
||||||
|
m->next = t;
|
||||||
|
m = t;
|
||||||
|
q = q->next; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>p
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("<EFBFBD>Ӵ<EFBFBD>С<EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>");
|
||||||
|
xianshi(H); // <20><>ʾ<EFBFBD>ϱ<EFBFBD>H
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ϊͷ<CEAA><CDB7>㣬<EFBFBD><E3A3AC>ͷָ<CDB7><D6B8>ֱ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
|
||||||
|
LinkList head = (LinkList)malloc(sizeof(LNode));
|
||||||
|
LinkList ji = (LinkList)malloc(sizeof(LNode));
|
||||||
|
LinkList ou = (LinkList)malloc(sizeof(LNode));
|
||||||
|
LinkList he = (LinkList)malloc(sizeof(LNode));
|
||||||
|
|
||||||
|
int choose = -1, n;
|
||||||
|
printf("*********************************************\n");
|
||||||
|
printf("********** ʵ<><CAB5>һ *******\n");
|
||||||
|
printf("*********************************************\n");
|
||||||
|
printf("********** 1.<2E><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 3.<2E>ֳ<EFBFBD><D6B3><EFBFBD>/ż<><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 4.<2E>ϲ<EFBFBD><CFB2>ɵݼ<C9B5><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 5.<2E><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 6.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *******\n");
|
||||||
|
printf("********** 7.<2E>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA> *******\n");
|
||||||
|
printf("********** 0.<2E>˳<EFBFBD> *******\n");
|
||||||
|
printf("*********************************************\n");
|
||||||
|
while (choose)
|
||||||
|
{
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>\n");
|
||||||
|
scanf("%d", &choose);
|
||||||
|
switch (choose)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
chushihua(head, ji, ou, he);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
||||||
|
scanf("%d", &n);
|
||||||
|
charu_1(head, n);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
fenbiao(head, ou, ji);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
hebiao(ji, ou, he);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
xianshi(head);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
Length(head);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
Emp(head);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
233
DataStructure/test2/实验二.cpp
Normal file
233
DataStructure/test2/实验二.cpp
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef struct PNode
|
||||||
|
{
|
||||||
|
int index; // 指数
|
||||||
|
int coe; // 系数
|
||||||
|
struct PNode *next; // 指针域
|
||||||
|
} PNode, *Polynomial;
|
||||||
|
|
||||||
|
void chushihua(Polynomial &L, Polynomial &M, Polynomial &N)
|
||||||
|
{
|
||||||
|
// todo list
|
||||||
|
L = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
M = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
N = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
L->next = NULL;
|
||||||
|
M->next = NULL;
|
||||||
|
N->next = NULL;
|
||||||
|
}
|
||||||
|
void Emp(Polynomial &L)
|
||||||
|
{
|
||||||
|
if (L->next == NULL)
|
||||||
|
printf("链表为空表。\n");
|
||||||
|
else
|
||||||
|
printf("链表为非空表。\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Length(Polynomial &L)
|
||||||
|
{
|
||||||
|
PNode *p;
|
||||||
|
int length = 0;
|
||||||
|
// todo list //while循环,不断往后移动p指针,并让length++
|
||||||
|
p = L;
|
||||||
|
while (p->next != NULL)
|
||||||
|
{
|
||||||
|
p = p->next;
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("链表长度为:%d\n", length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1、构造两个按指数递增的有序链表:插入节点,创建一元多项式
|
||||||
|
void charu_1(Polynomial &L)
|
||||||
|
{
|
||||||
|
PNode *q, *p;
|
||||||
|
int n;
|
||||||
|
printf("请输入你要创建的一元多项式的项数:\n");
|
||||||
|
scanf("%d", &n);
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
{
|
||||||
|
p = L;
|
||||||
|
q = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
printf("请输入第%d项的系数和指数:", i);
|
||||||
|
scanf("%d%d", &q->coe, &q->index);
|
||||||
|
q->next = NULL;
|
||||||
|
while (p->next != NULL && p->next->index < q->index)
|
||||||
|
{
|
||||||
|
// todo list p指针移动到最后一个结点位置
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
// todo list 将*q结点插入到*p结点后
|
||||||
|
q->next = p->next;
|
||||||
|
p->next = q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void xianshi(Polynomial &L)
|
||||||
|
{
|
||||||
|
PNode *p;
|
||||||
|
p = L;
|
||||||
|
while (p->next != NULL)
|
||||||
|
{
|
||||||
|
printf("%4d", p->next->coe); // 系数
|
||||||
|
printf("H");
|
||||||
|
printf("%d", p->next->index); // 指数
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2、两个一元多项式相加
|
||||||
|
void hebiao(Polynomial &J, Polynomial &O, Polynomial &H)
|
||||||
|
{
|
||||||
|
PNode *p = J->next, *q = O->next, *r = H, *s; // r是尾指针
|
||||||
|
while (p != NULL && q != NULL)
|
||||||
|
{
|
||||||
|
if (p->index < q->index)
|
||||||
|
{
|
||||||
|
s = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
// todo list //保存p指向结点的系数和指数到s所指向结点中的系数和指数中
|
||||||
|
s->coe = p->coe;
|
||||||
|
s->index = p->index;
|
||||||
|
// todo list //插入s所指向结点到r所指向结点的后面
|
||||||
|
s->next = NULL;
|
||||||
|
r->next = s;
|
||||||
|
|
||||||
|
r = s; // 更新尾指针
|
||||||
|
p = p->next; // 更新p指针
|
||||||
|
}
|
||||||
|
else if (p->index > q->index)
|
||||||
|
{
|
||||||
|
s = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
// todo list //保存q指向结点的系数和指数到s所指向结点中的系数和指数中
|
||||||
|
s->coe = q->coe;
|
||||||
|
s->index = q->index;
|
||||||
|
// todo list //插入s所指向结点到r所指向结点的后面
|
||||||
|
s->next = NULL;
|
||||||
|
r->next = s;
|
||||||
|
|
||||||
|
r = s; // 更新尾指针
|
||||||
|
q = q->next; // 更新q指针
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // 指数相等的情况
|
||||||
|
int sum = p->coe + q->coe;
|
||||||
|
if (sum != 0)
|
||||||
|
{
|
||||||
|
s = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
// todo list //保存p指向结点的指数到s所指向结点中的指数中
|
||||||
|
s->index = p->index;
|
||||||
|
// todo list //保存sum到s所指向结点中的系数中
|
||||||
|
s->coe = sum;
|
||||||
|
// todo list //插入s所指向结点到r所指向结点的后面
|
||||||
|
s->next = NULL;
|
||||||
|
r->next = s;
|
||||||
|
|
||||||
|
r = s; // 更新尾指针
|
||||||
|
}
|
||||||
|
p = p->next; // 更新p指针
|
||||||
|
q = q->next; // 更新q指针
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (p != NULL)
|
||||||
|
{ // J链表非空,还剩余有元素,把其剩余的元素插入到合表H链表后面
|
||||||
|
s = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
// todo list 尾插
|
||||||
|
s->coe = p->coe;
|
||||||
|
s->index = p->index;
|
||||||
|
s->next = NULL;
|
||||||
|
r->next = s;
|
||||||
|
r = s;
|
||||||
|
|
||||||
|
p = p->next; // 更新p指针
|
||||||
|
}
|
||||||
|
while (q != NULL)
|
||||||
|
{ // O链表非空,还剩余有元素,把其剩余的元素插入到合表H链表后面
|
||||||
|
s = (Polynomial)malloc(sizeof(PNode));
|
||||||
|
// todo list 尾插
|
||||||
|
s->coe = q->coe;
|
||||||
|
s->index = q->index;
|
||||||
|
s->next = NULL;
|
||||||
|
r->next = s;
|
||||||
|
r = s;
|
||||||
|
|
||||||
|
q = q->next; // 更新q指针
|
||||||
|
}
|
||||||
|
xianshi(H); // 新增
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Polynomial head[3];
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
head[i] = (Polynomial)malloc(sizeof(PNode)); // head[0]表示第一个一元多项式链表,head[1]为第二个一元多项式链表
|
||||||
|
}
|
||||||
|
|
||||||
|
int choose = -1, n;
|
||||||
|
printf("*********************************************************\n");
|
||||||
|
printf("********** 实验二 *******\n");
|
||||||
|
printf("*********************************************\n");
|
||||||
|
printf("********** 1.初始化单链表 *******\n");
|
||||||
|
printf("********** 2.建立递增链表(按指数递增) *******\n");
|
||||||
|
printf("********** 3.显示单链表整体 *******\n");
|
||||||
|
printf("********** 4.求单链表长度 *******\n");
|
||||||
|
printf("********** 5.判断单链表是否为空 *******\n");
|
||||||
|
printf("********** 6.求一元多项式的和 *******\n");
|
||||||
|
printf("********** 0.退出 *******\n");
|
||||||
|
printf("*********************************************************\n");
|
||||||
|
while (choose)
|
||||||
|
{
|
||||||
|
printf("请输入你的选择项:\n");
|
||||||
|
scanf("%d", &choose);
|
||||||
|
switch (choose)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
chushihua(head[0], head[1], head[2]);
|
||||||
|
printf("链表已经初始化。\n");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
printf("创建的第%d个一元多项式:\n", i + 1);
|
||||||
|
charu_1(head[i]); // 插入节点到指定链表
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
printf("显示第1个链表:");
|
||||||
|
xianshi(head[0]); // 显示第1个链表
|
||||||
|
printf("\n");
|
||||||
|
printf("显示第2个链表:");
|
||||||
|
xianshi(head[1]); // 显示第2个链表
|
||||||
|
printf("\n");
|
||||||
|
// xianshi(head[2]); // 显示第3个链表
|
||||||
|
// printf("\n");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
printf("计算第1个链表的长度:");
|
||||||
|
Length(head[0]); // 计算 第1个链表的长度
|
||||||
|
printf("计算第2个链表的长度:");
|
||||||
|
Length(head[1]); // 计算 第2个链表的长度
|
||||||
|
// Length(head[2]); //计算 第3个链表的长度
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
printf("判断第1个链表是否为空:");
|
||||||
|
Emp(head[0]); // 判断第1个链表是否为空
|
||||||
|
printf("判断第2个链表是否为空:");
|
||||||
|
Emp(head[1]); // 判断第2个链表是否为空
|
||||||
|
// Emp(head[2]); // 判断第3个链表是否为空
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
hebiao(head[0], head[1], head[2]);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // 程序正常退出时返回0
|
||||||
|
}
|
||||||
129
DataStructure/test3/实验三.cpp
Normal file
129
DataStructure/test3/实验三.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define MAXSIZE 10
|
||||||
|
typedef struct Queue
|
||||||
|
{
|
||||||
|
int *data; // 存储空间的基地址
|
||||||
|
int front, rear; // 头指针、尾指针
|
||||||
|
int count; // 新增一个 count变量,用于记录队中元素个数
|
||||||
|
} Queue;
|
||||||
|
|
||||||
|
// 初始化队列
|
||||||
|
void Init(Queue &Q)
|
||||||
|
{
|
||||||
|
Q.data = new int[MAXSIZE];
|
||||||
|
// todo list 处理front, rear指针,以及count变量
|
||||||
|
Q.front = 0;
|
||||||
|
Q.rear = 0;
|
||||||
|
Q.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 入队
|
||||||
|
void EnQueue(Queue &Q, int e)
|
||||||
|
{
|
||||||
|
if (Q.count >= MAXSIZE) // todo list //利用count判断队是否满
|
||||||
|
printf("队满\n"); // 【有坑,思考】
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// todo list //入队元素,尾指针+1
|
||||||
|
Q.data[Q.rear] = e;
|
||||||
|
Q.rear++;
|
||||||
|
// todo list //更新count值
|
||||||
|
Q.count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 出队
|
||||||
|
void DelQueue(Queue &Q, int &e)
|
||||||
|
{
|
||||||
|
if (Q.count == 0) // todo list //利用count判断队是否空
|
||||||
|
printf("队空\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// todo list //出队元素,头指针+1
|
||||||
|
e = Q.data[Q.front];
|
||||||
|
Q.front++;
|
||||||
|
// todo list //更新count值
|
||||||
|
Q.count--;
|
||||||
|
printf("出队元素为:%d\n", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断队空
|
||||||
|
void IsNull(Queue Q)
|
||||||
|
{
|
||||||
|
if (Q.count == 0) // todo list //利用count判断队是否空
|
||||||
|
printf("队空\n");
|
||||||
|
else
|
||||||
|
printf("队不空\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示整个队列
|
||||||
|
void Display(Queue Q)
|
||||||
|
{
|
||||||
|
while (Q.count > 0)
|
||||||
|
{
|
||||||
|
printf("%3d,", Q.data[Q.front]);
|
||||||
|
// todo list //头指针依次往后移动
|
||||||
|
Q.front++;
|
||||||
|
// todo list //更新count值
|
||||||
|
Q.count--;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Queue Q;
|
||||||
|
printf("------------------------------------\n");
|
||||||
|
printf("1.初始化队列\n");
|
||||||
|
printf("2.判断队列是否为空\n");
|
||||||
|
printf("3.入队\n");
|
||||||
|
printf("4.出队\n");
|
||||||
|
printf("5.显示整个队列\n");
|
||||||
|
printf("6.退出\n");
|
||||||
|
printf("------------------------------------\n");
|
||||||
|
int sel;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
printf("请输入选项:");
|
||||||
|
scanf("%d", &sel);
|
||||||
|
// getchar();
|
||||||
|
switch (sel)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
Init(Q);
|
||||||
|
printf("链表已经初始化。\n");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
IsNull(Q);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
int n, e;
|
||||||
|
printf("请输入入队元素个数:");
|
||||||
|
scanf("%d", &n);
|
||||||
|
printf("请输入需要入队的%d个元素:", n);
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
scanf("%d", &e);
|
||||||
|
EnQueue(Q, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
int e;
|
||||||
|
DelQueue(Q, e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
printf("队列为:");
|
||||||
|
Display(Q);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
27
README.md
Normal file
27
README.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## 在 `cqucc` 的一些代码
|
||||||
|
|
||||||
|
1. 目录结构
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── DataStructure # 数据结构
|
||||||
|
├── Server # Node.js 从基础到项目实践
|
||||||
|
├── Spider # Python 网络爬虫基础教程
|
||||||
|
└── Web # Web 前端开发技术
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 目录
|
||||||
|
- [数据结构](Web/README.md)
|
||||||
|
- [`Node.js` 从基础到项目实践](Web/README.md)
|
||||||
|
- [`Python` 网络爬虫基础教程](Spider/README.md)
|
||||||
|
- [`Web` 前端开发技术](Web/README.md)
|
||||||
|
|
||||||
|
## 📜 License
|
||||||
|
|
||||||
|
This project is licensed under the [MIT License](LICENSE).
|
||||||
14
Server/1/aa.js
Normal file
14
Server/1/aa.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
fs.readFile(__dirname + "/aa.txt", "utf8", (err, data) => {
|
||||||
|
if (err) return;
|
||||||
|
|
||||||
|
const content = data
|
||||||
|
.replace(/(\d+)[、.](?=\s*)/g, "$1、 ")
|
||||||
|
.replace(/([A-D])[.、](?=\s*)/g, "$1. ")
|
||||||
|
.replace(/\r?\n([B-D]\.)/g, "\t$1");
|
||||||
|
|
||||||
|
fs.writeFile(__dirname + "/new.txt", content, "utf8", (err) => {
|
||||||
|
if (err) return;
|
||||||
|
});
|
||||||
|
});
|
||||||
10
Server/1/aa.txt
Normal file
10
Server/1/aa.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
1、四大名著有哪些?
|
||||||
|
A.西游记
|
||||||
|
B.水浒传
|
||||||
|
C.三国演义
|
||||||
|
D.红楼梦
|
||||||
|
2.我们的口号
|
||||||
|
A、键盘敲烂、月薪过万
|
||||||
|
B、键盘生灰、垃圾一堆
|
||||||
|
C、键盘打烂
|
||||||
|
D、键盘放烂
|
||||||
4
Server/1/new.txt
Normal file
4
Server/1/new.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
1、 四大名著有哪些?
|
||||||
|
A. 西游记 B. 水浒传 C. 三国演义 D. 红楼梦
|
||||||
|
2、 我们的口号
|
||||||
|
A. 键盘敲烂、月薪过万 B. 键盘生灰、垃圾一堆 C. 键盘打烂 D. 键盘放烂
|
||||||
1
Server/2/.gitignore
vendored
Normal file
1
Server/2/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
text.txt
|
||||||
20
Server/2/README.md
Normal file
20
Server/2/README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## `Python` 网络爬虫基础教程
|
||||||
|
|
||||||
|
### 文件介绍
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── 1 # 课堂作业1
|
||||||
|
├── 2 # 课堂作业2
|
||||||
|
└── tests # 实验文件夹
|
||||||
|
├── test1 # 实验一
|
||||||
|
├── test2 # 实验二
|
||||||
|
└── test3 # 实验三
|
||||||
|
```
|
||||||
6
Server/2/main.js
Normal file
6
Server/2/main.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
const utils = require("./utils");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const text = fs.readFileSync(__dirname + "/text.txt", "utf8");
|
||||||
|
|
||||||
|
console.log(utils.word_count(text));
|
||||||
12
Server/2/utils.js
Normal file
12
Server/2/utils.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
const word_count = function (text) {
|
||||||
|
const text_list = text.replace(/[、\r?\n,,\s]+/g, " ").split(" ");
|
||||||
|
let word_obj = {};
|
||||||
|
for (const word of text_list) {
|
||||||
|
word_obj[word] = (word_obj[word] || 0) + 1;
|
||||||
|
}
|
||||||
|
return word_obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
word_count,
|
||||||
|
};
|
||||||
18
Server/README.md
Normal file
18
Server/README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## `Node.js` 从基础到项目实践
|
||||||
|
|
||||||
|
### 文件介绍
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── images # 图片资源
|
||||||
|
├── test1 # 实验一
|
||||||
|
├── test2 # 实验二
|
||||||
|
└── test3 # 实验三
|
||||||
|
```
|
||||||
133
Server/tests/test1/common.js
Normal file
133
Server/tests/test1/common.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
const os = require("os");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
// 格式化字节数为人类可读的单位
|
||||||
|
function formatBytes(bytes) {
|
||||||
|
const size = {
|
||||||
|
GB: 1024 * 1024 * 1024,
|
||||||
|
MB: 1024 * 1024,
|
||||||
|
KB: 1024,
|
||||||
|
B: 1,
|
||||||
|
};
|
||||||
|
for (const key in size) {
|
||||||
|
if (bytes >= size[key]) return `${bytes / size[key]} ${key}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数:统一处理路径分隔符为正斜杠
|
||||||
|
const formatPath = (pathStr) => {
|
||||||
|
return pathStr.replace(/\\/g, "/"); // 单个反斜杠替换为正斜杠
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. 操作系统基本信息
|
||||||
|
const getSystemInfo = () => {
|
||||||
|
return {
|
||||||
|
osType: os.type(),
|
||||||
|
osPlatform: os.platform(),
|
||||||
|
osVersion: os.release(),
|
||||||
|
osName: os.version(),
|
||||||
|
arch: os.arch(),
|
||||||
|
hostname: os.hostname(),
|
||||||
|
systemStartTime: new Date(os.uptime() * 1000).toLocaleDateString(),
|
||||||
|
systemRunningTime: `${Math.floor(os.uptime() / 3600)}小时 ${
|
||||||
|
Math.floor(os.uptime() % 3600) / 60
|
||||||
|
}分钟`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. CPU信息
|
||||||
|
const getCPUInfo = () => {
|
||||||
|
const cpus = os.cpus();
|
||||||
|
return {
|
||||||
|
number: cpus.length,
|
||||||
|
model: cpus[0].model,
|
||||||
|
speed: cpus[0].speed + "MHz",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. 内存信息
|
||||||
|
const getMemoryInfo = () => {
|
||||||
|
return {
|
||||||
|
total: formatBytes(os.totalmem()),
|
||||||
|
freeMemory: formatBytes(os.freemem()),
|
||||||
|
useMemory: formatBytes(os.totalmem() - os.freemem()),
|
||||||
|
useRate: `${Math.round((1 - os.freemem() / os.totalmem()) * 100)}%`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4. 用户信息
|
||||||
|
const getUserInfo = () => {
|
||||||
|
const userInfo = os.userInfo();
|
||||||
|
return {
|
||||||
|
userName: userInfo.username,
|
||||||
|
uid: userInfo.uid,
|
||||||
|
gid: userInfo.gid,
|
||||||
|
homeDir: formatPath(userInfo.homedir),
|
||||||
|
shell: userInfo.shell || "unknown",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 5. 目录信息
|
||||||
|
const getDirInfo = () => {
|
||||||
|
return {
|
||||||
|
homeDir: formatPath(os.homedir()),
|
||||||
|
tmpDir: formatPath(os.tmpdir()),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 6. 负载信息 (仅 Unix 系统有效)
|
||||||
|
const getDutyInfo = () => {
|
||||||
|
const loadavg = os.loadavg();
|
||||||
|
return {
|
||||||
|
min1: loadavg[0].toFixed(2),
|
||||||
|
min5: loadavg[1].toFixed(2),
|
||||||
|
min15: loadavg[2].toFixed(2),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 7. 网络接口信息
|
||||||
|
const getNetworkInterfaceInfo = () => {
|
||||||
|
const networkInterfaces = os.networkInterfaces();
|
||||||
|
const data = [];
|
||||||
|
for (const [interfaceName, interfaceInfo] of Object.entries(
|
||||||
|
networkInterfaces
|
||||||
|
)) {
|
||||||
|
let item;
|
||||||
|
interfaceInfo.forEach((info) => {
|
||||||
|
item = {
|
||||||
|
name: interfaceName,
|
||||||
|
family: info.family,
|
||||||
|
ip: info.address,
|
||||||
|
mac: info.mac,
|
||||||
|
localAddress: info.internal ? true : false,
|
||||||
|
netmask: info.netmask,
|
||||||
|
gateway: info.gateway,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
data.push(item);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAll = () => {
|
||||||
|
return {
|
||||||
|
SystemInfo: getSystemInfo(),
|
||||||
|
CPUInfo: getCPUInfo(),
|
||||||
|
MemoryInfo: getMemoryInfo(),
|
||||||
|
UserInfo: getUserInfo(),
|
||||||
|
DirInfo: getDirInfo(),
|
||||||
|
DutyInfo: getDutyInfo(),
|
||||||
|
NetworkInterfaceInfo: getNetworkInterfaceInfo(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getSystemInfo,
|
||||||
|
getCPUInfo,
|
||||||
|
getMemoryInfo,
|
||||||
|
getUserInfo,
|
||||||
|
getDirInfo,
|
||||||
|
getDutyInfo,
|
||||||
|
getNetworkInterfaceInfo,
|
||||||
|
getAll,
|
||||||
|
};
|
||||||
268
Server/tests/test1/index.html
Normal file
268
Server/tests/test1/index.html
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>系统指标详情</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
color: #2c3e50;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #34495e;
|
||||||
|
border-left: 4px solid #3498db;
|
||||||
|
padding-left: 10px;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
padding: 12px 15px;
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 1px solid #ecf0f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
color: #2c3e50;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.network-item {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-time {
|
||||||
|
text-align: right;
|
||||||
|
color: #7f8c8d;
|
||||||
|
font-size: 0.9em;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
|
||||||
|
table,
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
position: absolute;
|
||||||
|
top: -9999px;
|
||||||
|
left: -9999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border: 1px solid #ecf0f1;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 50%;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
td:before {
|
||||||
|
position: absolute;
|
||||||
|
left: 15px;
|
||||||
|
content: attr(data-label);
|
||||||
|
font-weight: 600;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>系统指标详情</h1>
|
||||||
|
<div class="update-time" id="updateTime"></div>
|
||||||
|
<div id="content"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let data = `@@@`;
|
||||||
|
|
||||||
|
// 解析数据并渲染页面
|
||||||
|
function renderData() {
|
||||||
|
const systemData = JSON.parse(data);
|
||||||
|
const content = document.getElementById('content');
|
||||||
|
let html = '';
|
||||||
|
|
||||||
|
// 更新时间
|
||||||
|
document.getElementById('updateTime').textContent = `最后更新: ${new Date().toLocaleString()}`;
|
||||||
|
|
||||||
|
// 1. 系统信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>1. 系统基础信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">操作系统类型</td><td data-label="数值">${systemData.SystemInfo.osType}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统平台</td><td data-label="数值">${systemData.SystemInfo.osPlatform}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统版本</td><td data-label="数值">${systemData.SystemInfo.osVersion}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统名称</td><td data-label="数值">${systemData.SystemInfo.osName}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统架构</td><td data-label="数值">${systemData.SystemInfo.arch}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">主机名</td><td data-label="数值">${systemData.SystemInfo.hostname}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统启动时间</td><td data-label="数值">${systemData.SystemInfo.systemStartTime} ${systemData.SystemInfo.systemStartTime === '1970/1/1' ? '(可能为数据异常)' : ''}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">系统运行时长</td><td data-label="数值">${systemData.SystemInfo.systemRunningTime}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 2. CPU信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>2. CPU信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">CPU核心数</td><td data-label="数值">${systemData.CPUInfo.number}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">CPU型号</td><td data-label="数值">${systemData.CPUInfo.model}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">CPU基础频率</td><td data-label="数值">${systemData.CPUInfo.speed}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 3. 内存信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>3. 内存信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">总内存</td><td data-label="数值">${systemData.MemoryInfo.total}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">空闲内存</td><td data-label="数值">${systemData.MemoryInfo.freeMemory}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">已使用内存</td><td data-label="数值">${systemData.MemoryInfo.useMemory}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">内存使用率</td><td data-label="数值">${systemData.MemoryInfo.useRate}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 4. 用户信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>4. 用户信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">用户名</td><td data-label="数值">${systemData.UserInfo.userName}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">用户ID(uid)</td><td data-label="数值">${systemData.UserInfo.uid} (Windows系统默认值)</td></tr>
|
||||||
|
<tr><td data-label="指标名称">用户组ID(gid)</td><td data-label="数值">${systemData.UserInfo.gid} (Windows系统默认值)</td></tr>
|
||||||
|
<tr><td data-label="指标名称">用户主目录</td><td data-label="数值">${systemData.UserInfo.homeDir}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">默认shell</td><td data-label="数值">${systemData.UserInfo.shell}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 5. 目录信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>5. 目录信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">用户主目录</td><td data-label="数值">${systemData.DirInfo.homeDir}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">临时目录</td><td data-label="数值">${systemData.DirInfo.tmpDir}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 6. 负载信息
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<h2>6. 系统负载信息</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>指标名称</th><th>数值</th></tr>
|
||||||
|
<tr><td data-label="指标名称">1分钟负载</td><td data-label="数值">${systemData.DutyInfo.min1}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">5分钟负载</td><td data-label="数值">${systemData.DutyInfo.min5}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">15分钟负载</td><td data-label="数值">${systemData.DutyInfo.min15}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// 7. 网络接口信息
|
||||||
|
html += `<div class="section"><h2>7. 网络接口信息</h2><div id="networkList">`;
|
||||||
|
systemData.NetworkInterfaceInfo.forEach(iface => {
|
||||||
|
html += `
|
||||||
|
<div class="network-item">
|
||||||
|
<h3>网络接口:${iface.name} ${iface.localAddress ? '(本地回环)' : ''}</h3>
|
||||||
|
<table>
|
||||||
|
<tr><td data-label="指标名称">网络协议</td><td data-label="数值">${iface.family}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">IP地址</td><td data-label="数值">${iface.ip}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">MAC地址</td><td data-label="数值">${iface.mac}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">是否本地地址</td><td data-label="数值">${iface.localAddress ? '是' : '否'}</td></tr>
|
||||||
|
<tr><td data-label="指标名称">子网掩码</td><td data-label="数值">${iface.netmask}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
html += `</div></div>`;
|
||||||
|
console.log(html);
|
||||||
|
|
||||||
|
content.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始渲染
|
||||||
|
renderData();
|
||||||
|
|
||||||
|
// 模拟数据更新(每5秒更新一次运行时间)
|
||||||
|
setInterval(() => {
|
||||||
|
const systemData = JSON.parse(data);
|
||||||
|
// 解析当前运行时间并增加1分钟
|
||||||
|
const timeMatch = systemData.SystemInfo.systemRunningTime.match(/(\d+)小时 (\d+\.\d+)分钟/);
|
||||||
|
if (timeMatch) {
|
||||||
|
const hours = parseInt(timeMatch[1]);
|
||||||
|
let minutes = parseFloat(timeMatch[2]) + 1;
|
||||||
|
|
||||||
|
// 处理分钟进位
|
||||||
|
if (minutes >= 60) {
|
||||||
|
minutes -= 60;
|
||||||
|
systemData.SystemInfo.systemRunningTime = `${hours + 1}小时 ${minutes.toFixed(15)}分钟`;
|
||||||
|
} else {
|
||||||
|
systemData.SystemInfo.systemRunningTime = `${hours}小时 ${minutes.toFixed(15)}分钟`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新内存使用率(随机波动1-2%)
|
||||||
|
const currentRate = parseInt(systemData.MemoryInfo.useRate);
|
||||||
|
const newRate = Math.max(10, Math.min(90, currentRate + (Math.random() > 0.5 ? 1 : -1)));
|
||||||
|
systemData.MemoryInfo.useRate = `${newRate}%`;
|
||||||
|
|
||||||
|
// 重新序列化数据
|
||||||
|
data = JSON.stringify(systemData);
|
||||||
|
// 重新渲染页面
|
||||||
|
renderData();
|
||||||
|
}
|
||||||
|
}, 5000); // 5秒更新一次
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
23
Server/tests/test1/server.js
Normal file
23
Server/tests/test1/server.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const http = require("http");
|
||||||
|
const fs = require("fs");
|
||||||
|
const common = require(__dirname + "/common");
|
||||||
|
|
||||||
|
const server = http.createServer();
|
||||||
|
|
||||||
|
server.on("request", (req, res) => {
|
||||||
|
fs.readFile("./index.html", { encoding: "utf8" }, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end("Error Loading File");
|
||||||
|
} else {
|
||||||
|
res.writeHead(200, {
|
||||||
|
"content-type": "text/html",
|
||||||
|
});
|
||||||
|
res.end(data.replace("@@@", JSON.stringify(common.getAll())));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(3000, () => {
|
||||||
|
console.log("server is running at http://127.0.0.1:3000");
|
||||||
|
});
|
||||||
14
Server/tests/test2/index.js
Normal file
14
Server/tests/test2/index.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const myModule = require("./myModule");
|
||||||
|
|
||||||
|
console.log("Auther: ", myModule.auther);
|
||||||
|
console.log(myModule.greet("Alice"));
|
||||||
|
console.log("Sum: ", myModule.add(3, 5));
|
||||||
|
|
||||||
|
const lodash = require("lodash");
|
||||||
|
|
||||||
|
const array = [1, 2, 3, 4, 5];
|
||||||
|
const result = lodash.reverse(array);
|
||||||
|
console.log("Reverse array: ", result);
|
||||||
|
|
||||||
|
const gt3 = array.filter((n) => lodash.gt(n, 3));
|
||||||
|
console.log("Greater than 3: ", gt3);
|
||||||
15
Server/tests/test2/myModule.js
Normal file
15
Server/tests/test2/myModule.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const auther = "harry";
|
||||||
|
|
||||||
|
const greet = (name) => {
|
||||||
|
return `Hello, ${name}!`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const add = (a, b) => {
|
||||||
|
return a + b;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
auther,
|
||||||
|
greet,
|
||||||
|
add
|
||||||
|
}
|
||||||
2
Server/tests/test3/.gitignore
vendored
Normal file
2
Server/tests/test3/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
pnpm-lock.yaml
|
||||||
16
Server/tests/test3/index.js
Normal file
16
Server/tests/test3/index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const express = require("express")
|
||||||
|
const { router } = require("./routes/useRoute")
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
app.use(express.json())
|
||||||
|
app.use(router)
|
||||||
|
|
||||||
|
|
||||||
|
app.listen("3000", (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log("server listen :3000");
|
||||||
|
})
|
||||||
18
Server/tests/test3/package.json
Normal file
18
Server/tests/test3/package.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "test3",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"packageManager": "pnpm@10.14.0",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"joi": "^18.0.1",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
}
|
||||||
|
}
|
||||||
100
Server/tests/test3/routes/useRoute.js
Normal file
100
Server/tests/test3/routes/useRoute.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
const express = require("express")
|
||||||
|
const { number } = require("joi")
|
||||||
|
const joi = require("joi")
|
||||||
|
const lodash = require("lodash")
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
router.get("/userId/:userId", (req, res) => {
|
||||||
|
const userId = req.params.userId;
|
||||||
|
const { err } = joi.number().validate(userId);
|
||||||
|
if (err) {
|
||||||
|
return res.status(400).send("Invaild UserID");
|
||||||
|
}
|
||||||
|
res.send(`user ID is ${userId}`);
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get("/userName", (req, res) => {
|
||||||
|
const { name } = req.query;
|
||||||
|
|
||||||
|
const schema = joi.object({
|
||||||
|
name: joi.string().min(2).max(20).required()
|
||||||
|
})
|
||||||
|
const { error } = schema.validate({ name })
|
||||||
|
if (error) {
|
||||||
|
return res.status(400).send("Invaild UserName");
|
||||||
|
}
|
||||||
|
res.send(`User name is ${name}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get("/profile", (req, res) => {
|
||||||
|
res.send("This is the user profile page.")
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get("/profile/setting", (req, res) => {
|
||||||
|
res.send("This is the user profile setting page.")
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: 'zs', course: 'app', score: 90 },
|
||||||
|
{ name: 'zs', course: 'java', score: 80 },
|
||||||
|
{ name: 'ls', course: 'app', score: 89 },
|
||||||
|
{ name: 'ls', course: 'java', score: 99 },
|
||||||
|
{ name: 'ww', course: 'app', score: 78 },
|
||||||
|
{ name: 'ww', course: 'java', score: 88 },
|
||||||
|
]
|
||||||
|
|
||||||
|
router.get("/myScoure", (req, res) => {
|
||||||
|
const { name } = req.query;
|
||||||
|
const schema = joi.object({
|
||||||
|
name: joi.string().min(2).max(20).required()
|
||||||
|
})
|
||||||
|
const { error } = schema.validate({ name });
|
||||||
|
if (error) {
|
||||||
|
return res.status(400).send("Invaild Name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataGroup = lodash(data).groupBy("name").get(name)
|
||||||
|
res.send(dataGroup)
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get("/showScoure", (req, res) => {
|
||||||
|
const dataOrder = lodash.orderBy(data, ["score"], orders = "desc");
|
||||||
|
// console.log(dataOrder);
|
||||||
|
const dataGroup = lodash(data).groupBy("name").map((a) => {
|
||||||
|
return {
|
||||||
|
name: a[0].name,
|
||||||
|
avg: lodash.mean(a.map(e => e.score)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
res.send(dataGroup);
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get("/mny", (_req, res) => {
|
||||||
|
const mnyData = [
|
||||||
|
{ name: '张三', mny: '9k' },
|
||||||
|
{ name: '随便', mny: 6666 },
|
||||||
|
{ name: '王五', mny: '1w' },
|
||||||
|
{ name: '李四', mny: 15000 },
|
||||||
|
]
|
||||||
|
const fixData = mnyData.map((d) =>
|
||||||
|
typeof d.mny === "string"
|
||||||
|
? {
|
||||||
|
name: d.name,
|
||||||
|
mny: parseInt(d.mny = d.mny.replace("w", "0000").replace("k", "000"))
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
name: d.name,
|
||||||
|
mny: parseInt(d.mny)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const finalData = fixData.filter(d => lodash.gte(d.mny, 9000));
|
||||||
|
|
||||||
|
res.send(finalData)
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
router
|
||||||
|
}
|
||||||
|
|
||||||
1
Spider/.gitignore
vendored
Normal file
1
Spider/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
data.csv
|
||||||
15
Spider/README.md
Normal file
15
Spider/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## `Python` 网络爬虫基础教程
|
||||||
|
|
||||||
|
### 文件介绍
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
└── test1.py # 获取研招网数据
|
||||||
|
```
|
||||||
74
Spider/test1.py
Normal file
74
Spider/test1.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import csv
|
||||||
|
import requests
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
|
||||||
|
class YXZS:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.url = "https://yz.chsi.com.cn/sch/?start={}"
|
||||||
|
self.file = open("./data.csv", "+a", encoding="utf-8", newline="")
|
||||||
|
self.file.write("学校名称,学校性质,招生简章的链接,调剂办法的链接\n")
|
||||||
|
|
||||||
|
def get_html(self, page=1):
|
||||||
|
resp = requests.get(
|
||||||
|
self.url.format((page - 1) * 20),
|
||||||
|
headers={
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0",
|
||||||
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||||
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
return resp.text
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def parse_html(self, html_text: str):
|
||||||
|
html = etree.HTML(html_text)
|
||||||
|
schs = html.xpath('//div[@class="sch-item"]')
|
||||||
|
for sch in schs:
|
||||||
|
item = {
|
||||||
|
"name": (
|
||||||
|
sch.xpath(
|
||||||
|
'.//a[@class="name js-yxk-yxmc text-decoration-none"]/text()'
|
||||||
|
)[0].strip()
|
||||||
|
if sch.xpath(
|
||||||
|
'.//a[@class="name js-yxk-yxmc text-decoration-none"]/text()'
|
||||||
|
)
|
||||||
|
else "unkonwn"
|
||||||
|
),
|
||||||
|
"tag": (
|
||||||
|
sch.xpath('.//span[@class="sch-tag"]/text()')[0].strip()
|
||||||
|
if sch.xpath('.//span[@class="sch-tag"]/text()')
|
||||||
|
else "unkonwn"
|
||||||
|
),
|
||||||
|
"href1": (
|
||||||
|
"https://yz.chsi.com.cn"
|
||||||
|
+ sch.xpath('.//div[@class="sch-link"]/a[2]/@href')[0]
|
||||||
|
if sch.xpath('.//div[@class="sch-link"]/a[2]/@href')
|
||||||
|
else "unkonwn"
|
||||||
|
),
|
||||||
|
"href2": (
|
||||||
|
"https://yz.chsi.com.cn"
|
||||||
|
+ sch.xpath('.//div[@class="sch-link"]/a[4]/@href')[0]
|
||||||
|
if sch.xpath('.//div[@class="sch-link"]/a[4]/@href')
|
||||||
|
else "unkonwn"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
self.save_data(item)
|
||||||
|
|
||||||
|
def save_data(self, item):
|
||||||
|
writer = csv.DictWriter(self.file, fieldnames=item.keys())
|
||||||
|
writer.writerow(item)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
for i in range(0, 47):
|
||||||
|
print("正在获取第{}页".format(i + 1))
|
||||||
|
html_text = self.get_html(page=i)
|
||||||
|
if html_text == "":
|
||||||
|
print("第{}页获取的内容为空")
|
||||||
|
continue
|
||||||
|
self.parse_html(html_text)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
YXZS().run()
|
||||||
18
Web/README.md
Normal file
18
Web/README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) 2025 zhilv
|
||||||
|
|
||||||
|
This software is released under the MIT License.
|
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
-->
|
||||||
|
|
||||||
|
## `Web` 前端开发技术
|
||||||
|
|
||||||
|
### 文件介绍
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.
|
||||||
|
├── images # 图片资源
|
||||||
|
├── test1 # 实验一
|
||||||
|
├── test2 # 实验二
|
||||||
|
└── test3 # 实验三
|
||||||
|
```
|
||||||
BIN
Web/images/relax.png
Normal file
BIN
Web/images/relax.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 594 KiB |
26
Web/test1/plan.html
Normal file
26
Web/test1/plan.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>我的待办事项与学习资源</h1>
|
||||||
|
<ol>
|
||||||
|
<li>周一: 完成工作报告</li>
|
||||||
|
<li>周二: 参加项目会议</li>
|
||||||
|
<li>周三: 准备新方案的资料收集</li>
|
||||||
|
</ol>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://www.runoob.com/" target="_blank">菜鸟教程</a></li>
|
||||||
|
<li><a href="https://www.w3school.com.cn/" target="_blank">w3school</a></li>
|
||||||
|
<li><a href="https://www.bilibili.com/" target="_blank">B站</a></li>
|
||||||
|
</ul>
|
||||||
|
<p>版权所有 © zhilv</p>
|
||||||
|
<img src="../images/relax.png" alt="图片">
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
36
Web/test1/poem.html
Normal file
36
Web/test1/poem.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
p {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>李白《静夜思》赏析</h1>
|
||||||
|
<p><em>《静夜思》</em>是唐代诗人李白的经典诗作,它短小精悍,却蕴含着深深的思乡之情。</p>
|
||||||
|
|
||||||
|
<h2>原诗内容</h2>
|
||||||
|
<p><strong>床前</strong>明月光,<br>
|
||||||
|
疑是地上霜。<br>
|
||||||
|
举头<sup>①</sup>望明月,<br>
|
||||||
|
低头思故乡。</p>
|
||||||
|
|
||||||
|
<p> 在诗中,“床前”这个词被加粗(床前),起到了一定的强调作用,让读者首先注意到诗人所处的位置。<br>
|
||||||
|
而“疑是地上霜”这句诗,通过“霜”这个字形象地描绘出月光的皎洁清冷,仿佛地上结了一层霜,这种感觉通过简单的文字就传达给了读者。<br>
|
||||||
|
当诗人“举头①望明月”时,这里的上标数字①可以用来做注释标记,表示对“举头”这个动作可能存在的特殊解读或者引用来源等,明月成为了引发思乡之情的重要媒介。<br>
|
||||||
|
最后“低头思故乡”,诗人深沉地(用em标签表示情感上的强调)陷入对故乡的思念之中。</p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<p>这首诗虽然没有华丽的辞藻,但每一个字都像是经过精心雕琢,<strong>强烈地(用strong标签表示语义上的强调)</strong>触动着读者内心深处的思乡情感,成为了千古流传的佳作。</p>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
53
Web/test2/attri_practice.html
Normal file
53
Web/test2/attri_practice.html
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
color: #cc0000;
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tit {
|
||||||
|
background-color: gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tit {
|
||||||
|
text-align: center;
|
||||||
|
font-style: italic;
|
||||||
|
font-family: "宋体";
|
||||||
|
}
|
||||||
|
|
||||||
|
a:link {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: red;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:active {
|
||||||
|
color: rgb(0, 204, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
a:after {
|
||||||
|
color: #9900ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
[title] {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<p id="tit" class="tit" title="tit">一个段落</p>
|
||||||
|
<a href="https://www.runoob.com/" target="_blank">点击跳转到菜鸟教程</a>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
23
Web/test2/news.html
Normal file
23
Web/test2/news.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>新闻</title>
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
letter-spacing: 6px;
|
||||||
|
line-height: 2em;
|
||||||
|
text-indent: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<p> 昨天上午,南京国际博览中心金陵会议中心内欢声笑语,春意盎然,省委、省政府在这里举行春节团拜会。
|
||||||
|
Yesterday morning, the Jinling Conference Center of Nanjing International Expo Center was filled with laughter
|
||||||
|
and joy, and the provincial party committee and government held a Spring Festival gathering here.</p>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
39
Web/test2/product.html
Normal file
39
Web/test2/product.html
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
text-decoration: underline;
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sc {
|
||||||
|
text-decoration: line-through;
|
||||||
|
text-transform: lowercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gz {
|
||||||
|
text-decoration: overline;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h3>设置文字装饰及大小写转换</h3>
|
||||||
|
<p>Chongqing, abbreviated as "Yu", is a municipality directly under the central and western regions of China, famous
|
||||||
|
for its mountainous city characteristics, hotpot culture, and the beautiful scenery of the confluence of the
|
||||||
|
Yangtze River and Jialing River.</p>
|
||||||
|
<p id="sc">Sichuan, abbreviated as "Chuan" or "Shu", is located in southwestern China and is a province known for
|
||||||
|
its
|
||||||
|
magnificent natural scenery, rich cultural heritage, and spicy cuisine.</p>
|
||||||
|
<p class="gz">Guizhou, abbreviated as "Qian" or "Gui", is located in southwestern China and is a province renowned
|
||||||
|
for its
|
||||||
|
diverse ethnic cultures, spectacular karst landforms, and beautiful natural landscapes.</p>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
77
Web/test3/table.html
Normal file
77
Web/test3/table.html
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="./tableTitle.css">
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
width: 600px;
|
||||||
|
height: 400px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
border-spacing: 0px;
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody tr:nth-child(odd) {
|
||||||
|
background-color: #CDF8F9;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbody tr:nth-child(even) {
|
||||||
|
background-color: #FDEFBB;
|
||||||
|
}
|
||||||
|
.xn {
|
||||||
|
background-color: rgb(255, 255, 134);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<table align="center" cellpadding="5">
|
||||||
|
<caption>简易学生表</caption>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>姓名</td>
|
||||||
|
<td>单位</td>
|
||||||
|
<td>学号</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td rowspan="4" class="xn">2024-2025学年</td>
|
||||||
|
<td>王小品</td>
|
||||||
|
<td>商学院</td>
|
||||||
|
<td>110204</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>李中</td>
|
||||||
|
<td>财经学院</td>
|
||||||
|
<td>120204</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>胡三</td>
|
||||||
|
<td>大数据学院</td>
|
||||||
|
<td>130504</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>李白</td>
|
||||||
|
<td>人工智能学院</td>
|
||||||
|
<td>100244</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" style="background-color: white;">重庆城市科技学院</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
7
Web/test3/tableTitle.css
Normal file
7
Web/test3/tableTitle.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
caption {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
color: #0daeba;
|
||||||
|
background-color: bisque;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user