commit 013ba04706c6f75dc978ce636074f583644be41e Author: 刘航宇 <3364451258@qq.com> Date: Wed May 6 11:44:00 2026 +0800 初始提交 diff --git a/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/CodeChunks.db b/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/CodeChunks.db new file mode 100644 index 0000000..8930592 Binary files /dev/null and b/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/CodeChunks.db differ diff --git a/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/SemanticSymbols.db b/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/SemanticSymbols.db new file mode 100644 index 0000000..b4c199c Binary files /dev/null and b/.vs/Cpp_Code/CopilotIndices/17.14.1204.46620/SemanticSymbols.db differ diff --git a/.vs/Cpp_Code/FileContentIndex/2f1f339f-4c0b-40ad-a077-c960ad81d867.vsidx b/.vs/Cpp_Code/FileContentIndex/2f1f339f-4c0b-40ad-a077-c960ad81d867.vsidx new file mode 100644 index 0000000..f25103b Binary files /dev/null and b/.vs/Cpp_Code/FileContentIndex/2f1f339f-4c0b-40ad-a077-c960ad81d867.vsidx differ diff --git a/.vs/Cpp_Code/v17/.wsuo b/.vs/Cpp_Code/v17/.wsuo new file mode 100644 index 0000000..23522d8 Binary files /dev/null and b/.vs/Cpp_Code/v17/.wsuo differ diff --git a/.vs/Cpp_Code/v17/Browse.VC.db b/.vs/Cpp_Code/v17/Browse.VC.db new file mode 100644 index 0000000..048fd0f Binary files /dev/null and b/.vs/Cpp_Code/v17/Browse.VC.db differ diff --git a/.vs/Cpp_Code/v17/DocumentLayout.backup.json b/.vs/Cpp_Code/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..2e6b9cf --- /dev/null +++ b/.vs/Cpp_Code/v17/DocumentLayout.backup.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\Code\\Cpp_Code\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/.vs/Cpp_Code/v17/DocumentLayout.json b/.vs/Cpp_Code/v17/DocumentLayout.json new file mode 100644 index 0000000..8e40e2d --- /dev/null +++ b/.vs/Cpp_Code/v17/DocumentLayout.json @@ -0,0 +1,37 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\Code\\Cpp_Code\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|D:\\Code\\Cpp_Code\\\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", + "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp", + "DocumentMoniker": "D:\\Code\\Cpp_Code\\\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp", + "RelativeDocumentMoniker": "\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp", + "ToolTip": "D:\\Code\\Cpp_Code\\\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp", + "RelativeToolTip": "\u6570\u636E\u7ED3\u6784\\\u7ED3\u6784\u4F53\u5B9E\u73B0\u63D2\u5165\u5143\u7D20.cpp", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAB4AAAATAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|", + "WhenOpened": "2025-10-10T01:18:40.327Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..e257ff9 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": "无配置" +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..52cddeb --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,8 @@ +{ + "ExpandedNodes": [ + "", + "\\数据结构" + ], + "SelectedNode": "\\数据结构\\结构体实现插入元素.cpp", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..7010445 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..21ea33a --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,27 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "D:/settings/Language/C/mingw64/bin/g++.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "-Wall", + "-Wextra", + "-Wshadow", + "-fsanitize=address", + "-g3" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c6a541f --- /dev/null +++ b/.vscode/launch.json @@ -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/Cpp_Code/数据结构", + "program": "d:/Code/Cpp_Code/数据结构/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7b08d16 --- /dev/null +++ b/.vscode/settings.json @@ -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": {} +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..3697bf7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,35 @@ +{ + "tasks": + [ + { + "type": "shell", + "label": "C/C++: gcc.exe 生成活动文件", + "command": "D:\\settings\\Language\\C\\mingw64\\bin\\g++.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" +} \ No newline at end of file diff --git a/数据结构/output/数组.exe b/数据结构/output/数组.exe new file mode 100644 index 0000000..e0073d1 Binary files /dev/null and b/数据结构/output/数组.exe differ diff --git a/数据结构/output/结构体实现插入元素.exe b/数据结构/output/结构体实现插入元素.exe new file mode 100644 index 0000000..77954fb Binary files /dev/null and b/数据结构/output/结构体实现插入元素.exe differ diff --git a/数据结构/数组.cpp b/数据结构/数组.cpp new file mode 100644 index 0000000..c702bf0 --- /dev/null +++ b/数据结构/数组.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +void insert(int insertPos, int insertPos, int newValue){ + // 将插入位置后的元素向后移动一位 + for (int i = size; i > insertPos; i--) { + arr[i] = arr[i - 1]; + } + + // 插入新元素到目标位置 + arr[insertPos] = newValue; + + size++; // 更新数组元素个数 +} + +int main() { + int arr[100] = {1, 2, 3, 4, 5}; // 定义一个初始数组 + int size = 5; // 数组的当前元素个数 + int insertPos = 2; // 要插入元素的位置 + int newValue = 10; // 要插入的新元素 + + insert(insertPos, insertPos, newValue); + + // 输出插入后的数组 + for (int i = 0; i < size; i++) + { + cout << arr[i] << " "; + } + + return 0; +} \ No newline at end of file diff --git a/数据结构/结构体实现插入元素.cpp b/数据结构/结构体实现插入元素.cpp new file mode 100644 index 0000000..b7ea59f --- /dev/null +++ b/数据结构/结构体实现插入元素.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; + +// 定义结构体 +struct MyArray +{ + int arr[100]; // 数组,假设最大长度为100 + int size; // 数组当前元素数量 +}; + +// 插入函数,作为结构体外部的成员函数 +void insert(MyArray &myArray, int position, int value) +{ + if (position < 0 || position > myArray.size || myArray.size >= 100) + { + // 处理错误情况,例如位置无效或数组已满 + cout << "无效位置或者数组已满" << endl; + return; + } + + // 将从插入位置开始的元素向后移动一位 + for (int i = myArray.size; i > position; i--) + { + myArray.arr[i] = myArray.arr[i - 1]; + } + + // 在指定位置插入新值 + myArray.arr[position] = value; + + // 更新数组大小 + myArray.size++; +} + +// 打印函数,作为结构体外部的成员函数 +void print(const MyArray &myArray) +{ + for (int i = 0; i < myArray.size; i++) + { + cout << myArray.arr[i] << " "; + } + cout << endl; +} + +int main() +{ + MyArray myArray; // 创建MyArray实例 + + // 初始化数组和size + for (int i = 0; i < 5; i++) + { + myArray.arr[i] = i + 1; + } + myArray.size = 5; // 设置数组当前大小 + + // 在指定位置插入新值 + int insertPos = 2; + int newValue = 10; + insert(myArray, insertPos, newValue); + + // 打印数组 + print(myArray); + + return 0; +}