Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6429ae798f | |||
| e1fcb9b565 | |||
| a950a73c81 | |||
| f127396a63 | |||
| 93c16edb5a | |||
| e691ab43cc | |||
| 5e874ceb80 | |||
| ed6113b2f1 | |||
| 5510a78cc9 | |||
| dc70efb5bc | |||
| 12412b3864 | |||
| af63d6c2c9 | |||
| 247f41ff87 | |||
| 91e3438bfb | |||
| 5b7eccf414 | |||
| 127ecdab8f | |||
| c9e57b4d41 | |||
| ac374e89bf | |||
| 4f7a07025a |
+1
-1
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
# 排除IDE配置文件
|
# 排除IDE配置文件
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
|
||||||
.vs/
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# 排除Trae AI配置文件
|
# 排除Trae AI配置文件
|
||||||
.trae/
|
.trae/
|
||||||
|
|||||||
Vendored
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "windows-gcc-x64",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE"
|
||||||
|
],
|
||||||
|
"compilerPath": "D:/Program Files/mingw64/bin/gcc.exe",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
|
"compilerArgs": [
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Wshadow",
|
||||||
|
"-fsanitize=address",
|
||||||
|
"-g3"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "C/C++ Runner: Debug Session",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"externalConsole": true,
|
||||||
|
"cwd": "d:/Code/C_code/数据结构/陈越数据结构",
|
||||||
|
"program": "d:/Code/C_code/数据结构/陈越数据结构/build/Debug/outDebug",
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerPath": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+60
@@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||||
|
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||||
|
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||||
|
"C_Cpp_Runner.cStandard": "c17",
|
||||||
|
"C_Cpp_Runner.cppStandard": "c++17",
|
||||||
|
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||||
|
"C_Cpp_Runner.useMsvc": false,
|
||||||
|
"C_Cpp_Runner.warnings": [
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Wpedantic",
|
||||||
|
"-Wshadow",
|
||||||
|
"-Wformat=2",
|
||||||
|
"-Wcast-align",
|
||||||
|
"-Wconversion",
|
||||||
|
"-Wsign-conversion",
|
||||||
|
"-Wnull-dereference"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.msvcWarnings": [
|
||||||
|
"/W4",
|
||||||
|
"/permissive-",
|
||||||
|
"/w14242",
|
||||||
|
"/w14287",
|
||||||
|
"/w14296",
|
||||||
|
"/w14311",
|
||||||
|
"/w14826",
|
||||||
|
"/w44062",
|
||||||
|
"/w44242",
|
||||||
|
"/w14905",
|
||||||
|
"/w14906",
|
||||||
|
"/w14263",
|
||||||
|
"/w44265",
|
||||||
|
"/w14928"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.enableWarnings": true,
|
||||||
|
"C_Cpp_Runner.warningsAsError": false,
|
||||||
|
"C_Cpp_Runner.compilerArgs": [],
|
||||||
|
"C_Cpp_Runner.linkerArgs": [],
|
||||||
|
"C_Cpp_Runner.includePaths": [],
|
||||||
|
"C_Cpp_Runner.includeSearch": [
|
||||||
|
"*",
|
||||||
|
"**/*"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.excludeSearch": [
|
||||||
|
"**/build",
|
||||||
|
"**/build/**",
|
||||||
|
"**/.*",
|
||||||
|
"**/.*/**",
|
||||||
|
"**/.vscode",
|
||||||
|
"**/.vscode/**"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||||
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
|
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||||
|
"files.associations": {}
|
||||||
|
}
|
||||||
Vendored
+35
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"tasks":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "C/C++: gcc.exe 生成活动文件",
|
||||||
|
"command": "D:\\Program Files\\mingw64\\bin\\gcc.exe",
|
||||||
|
"args":
|
||||||
|
[
|
||||||
|
"-fdiagnostics-color=always",
|
||||||
|
"-g",
|
||||||
|
"${file}",
|
||||||
|
"-o",
|
||||||
|
"${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||||
|
"-Wall",
|
||||||
|
"-Werror",
|
||||||
|
"-std=c++17",
|
||||||
|
"-fsanitize=address",
|
||||||
|
"-static-libasan"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${fileDirname}"
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"detail": "调试器生成的任务。"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
||||||
@@ -16,6 +16,4 @@ int main()
|
|||||||
}
|
}
|
||||||
printf("%d\n",n);
|
printf("%d\n",n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <direct.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链表操作示例程序
|
||||||
|
*
|
||||||
|
* 本程序演示了单向链表的基本操作:
|
||||||
|
* 1. 创建链表并添加节点
|
||||||
|
* 2. 遍历并打印链表
|
||||||
|
* 3. 在链表中查找特定值
|
||||||
|
* 4. 从链表中删除特定值的节点
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _node
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
struct _node *next;
|
||||||
|
} Node;
|
||||||
|
|
||||||
|
typedef struct _list
|
||||||
|
{
|
||||||
|
Node *head;
|
||||||
|
Node *tail;
|
||||||
|
} List;
|
||||||
|
|
||||||
|
void add(List *pList, int value)
|
||||||
|
{
|
||||||
|
Node *p = (Node *)malloc(sizeof(Node));
|
||||||
|
p->value = value;
|
||||||
|
p->next = NULL;
|
||||||
|
// 将节点插入链表
|
||||||
|
Node *last = pList->head;
|
||||||
|
if (last != NULL)
|
||||||
|
{
|
||||||
|
while (last->next != NULL)
|
||||||
|
{
|
||||||
|
last = last->next;
|
||||||
|
}
|
||||||
|
// attach
|
||||||
|
last->next = p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pList->head = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(List *pList)
|
||||||
|
{
|
||||||
|
Node *p;
|
||||||
|
for (p = pList->head; p; p = p->next)
|
||||||
|
{
|
||||||
|
printf("%d\t", p->value);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// 设置控制台编码为UTF-8
|
||||||
|
#ifdef _WIN32
|
||||||
|
system("chcp 65001 > nul"); // 设置控制台编码为UTF-8
|
||||||
|
SetConsoleOutputCP(65001); // 设置控制台输出编码
|
||||||
|
SetConsoleCP(65001); // 设置控制台输入编码
|
||||||
|
#endif
|
||||||
|
|
||||||
|
List list;
|
||||||
|
list.head = NULL;
|
||||||
|
list.tail = NULL;
|
||||||
|
int number;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("请输入一个整数:");
|
||||||
|
scanf("%d", &number);
|
||||||
|
if (number != -1)
|
||||||
|
{
|
||||||
|
|
||||||
|
add(&list, number);
|
||||||
|
}
|
||||||
|
} while (number != -1);
|
||||||
|
print(&list);
|
||||||
|
|
||||||
|
scanf("%d", &number);
|
||||||
|
Node *p;
|
||||||
|
int isFound = 0;
|
||||||
|
for (p = list.head; p; p = p->next)
|
||||||
|
{
|
||||||
|
if (p->value == number)
|
||||||
|
{
|
||||||
|
printf("找到!\n");
|
||||||
|
isFound = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isFound)
|
||||||
|
{
|
||||||
|
printf("未找到!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *q;
|
||||||
|
for (q = NULL, p = list.head; p; q = p, p = p->next)
|
||||||
|
{
|
||||||
|
if (p->value == number)
|
||||||
|
{
|
||||||
|
if (q == NULL)
|
||||||
|
{
|
||||||
|
list.head = p->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
q->next = p->next;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
printf("删除成功!\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -46,6 +46,16 @@ void add(List* pList, int value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(List* pList)
|
||||||
|
{
|
||||||
|
Node *p;
|
||||||
|
for (p=pList->head; p; p=p->next)
|
||||||
|
{
|
||||||
|
printf("%d\t", p->value);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// 设置控制台编码为UTF-8
|
// 设置控制台编码为UTF-8
|
||||||
@@ -69,6 +79,24 @@ int main()
|
|||||||
|
|
||||||
}
|
}
|
||||||
} while (number!=-1);
|
} while (number!=-1);
|
||||||
|
print(&list);
|
||||||
|
|
||||||
|
scanf("%d", &number);
|
||||||
|
Node *p;
|
||||||
|
int isFound = 0;
|
||||||
|
for (p=list.head; p; p=p->next)
|
||||||
|
{
|
||||||
|
if (p->value==number)
|
||||||
|
{
|
||||||
|
printf("找到!\n");
|
||||||
|
isFound = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isFound)
|
||||||
|
{
|
||||||
|
printf("未找到!\n");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <direct.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// !链表的清除
|
||||||
|
/*
|
||||||
|
1. 清除链表中的所有节点
|
||||||
|
2. 释放链表占用的内存
|
||||||
|
2.1 使用malloc申请的动态内存需要释放
|
||||||
|
2.2 用malloc申请的内存,即使没有赋值,也会被赋值一个特定的值
|
||||||
|
赋值就是使用,所以没必要为这种内存清空赋值
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _node{
|
||||||
|
int value;
|
||||||
|
struct _node *next;
|
||||||
|
} Node;
|
||||||
|
|
||||||
|
typedef struct _list{
|
||||||
|
Node *head;
|
||||||
|
Node *tail;
|
||||||
|
} List;
|
||||||
|
|
||||||
|
void add(List* pList, int value)
|
||||||
|
{
|
||||||
|
Node *p=(Node*)malloc(sizeof(Node));
|
||||||
|
p->value = value;
|
||||||
|
p->next = NULL;
|
||||||
|
// 将节点插入链表
|
||||||
|
Node *last = pList->head;
|
||||||
|
if (last!=NULL)
|
||||||
|
{
|
||||||
|
while (last->next!=NULL)
|
||||||
|
{
|
||||||
|
last = last->next;
|
||||||
|
}
|
||||||
|
// attach
|
||||||
|
last->next = p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pList->head = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(List* pList)
|
||||||
|
{
|
||||||
|
Node *p;
|
||||||
|
for (p=pList->head; p; p=p->next)
|
||||||
|
{
|
||||||
|
printf("%d\t", p->value);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// 设置控制台编码为UTF-8
|
||||||
|
#ifdef _WIN32
|
||||||
|
system("chcp 65001 > nul"); // 设置控制台编码为UTF-8
|
||||||
|
SetConsoleOutputCP(65001); // 设置控制台输出编码
|
||||||
|
SetConsoleCP(65001); // 设置控制台输入编码
|
||||||
|
#endif
|
||||||
|
|
||||||
|
List list;
|
||||||
|
list.head = NULL;
|
||||||
|
list.tail = NULL;
|
||||||
|
int number;
|
||||||
|
do {
|
||||||
|
printf("请输入一个整数:");
|
||||||
|
scanf("%d", &number);
|
||||||
|
if (number!=-1)
|
||||||
|
{
|
||||||
|
|
||||||
|
add(&list, number);
|
||||||
|
|
||||||
|
}
|
||||||
|
} while (number!=-1);
|
||||||
|
print(&list);
|
||||||
|
|
||||||
|
scanf("%d", &number);
|
||||||
|
Node *p;
|
||||||
|
int isFound = 0;
|
||||||
|
for (p=list.head; p; p=p->next)
|
||||||
|
{
|
||||||
|
if (p->value==number)
|
||||||
|
{
|
||||||
|
printf("找到!\n");
|
||||||
|
isFound = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isFound)
|
||||||
|
{
|
||||||
|
printf("未找到!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *q;
|
||||||
|
for (q = NULL, p = list.head; p; q=p, p = p->next)
|
||||||
|
{
|
||||||
|
if (p->value == number)
|
||||||
|
{
|
||||||
|
if (q==NULL)
|
||||||
|
{
|
||||||
|
list.head = p->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
q->next = p->next;
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
printf("删除成功!\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (p=list.head; p; p=p)
|
||||||
|
{
|
||||||
|
q=p->next;
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user