初始提交
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"Version": 1,
|
||||||
|
"WorkspaceRootPath": "D:\\Code\\Cpp_Code\\",
|
||||||
|
"Documents": [],
|
||||||
|
"DocumentGroupContainers": [
|
||||||
|
{
|
||||||
|
"Orientation": 0,
|
||||||
|
"VerticalTabListWidth": 256,
|
||||||
|
"DocumentGroups": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"CurrentProjectSetting": "无配置"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"ExpandedNodes": [
|
||||||
|
"",
|
||||||
|
"\\数据结构"
|
||||||
|
],
|
||||||
|
"SelectedNode": "\\数据结构\\结构体实现插入元素.cpp",
|
||||||
|
"PreviewInSolutionExplorer": false
|
||||||
|
}
|
||||||
Binary file not shown.
Vendored
+27
@@ -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
|
||||||
|
}
|
||||||
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/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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
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:\\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"
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include <iostream>
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user