commit 1059058706fbaf6fc2943a79bdd8bfb4737fea41 Author: iridiumR Date: Sun Oct 3 10:28:37 2021 +0800 作业罢了 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59c7a36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.exe +tempCodeRunnerFile.cpp \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..9eb1bea --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,23 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:/Project/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", + "C:/Project/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", + "C:/Project/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:/Project/mingw64/bin/gcc.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..81c909b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "gcc.exe", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "args": [], + "stopAtEntry": false, + "cwd": "C:/Project/mingw64/bin", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "C:\\Project\\mingw64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "为 gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: gcc.exe 生成活动文件" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b681993 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "C_Cpp.errorSquiggles": "Enabled", + "files.encoding": "gb2312" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..102eb71 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe 生成活动文件", + "command": "C:/Project/mingw64/bin/gcc.exe", + "args": [ + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "C:/Project/mingw64/bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "调试器生成的任务。" + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/ex1.cpp b/ex1.cpp new file mode 100644 index 0000000..6c34b1f --- /dev/null +++ b/ex1.cpp @@ -0,0 +1,114 @@ +#include +// #include +#include +#include + +#define LENGTH 10000 +//鳤 + +#define OUTPUT +//Ƿ + +// #define RANDOM +// + + +#define MODE_1 +//MODE_1: +//MODE_2: ݹ + + +int a[LENGTH]; +void init() +{ + #ifdef RANDOM + srand(time(NULL)); + #endif + + for(int i = 0 ; i < LENGTH ; i++) + + #ifdef RANDOM + a[i]=1+rand()%LENGTH; + #else + a[i]=LENGTH-i; + #endif +} + +void swap(int *a,int *b) +{ + int c = *a; + *a = *b; + *b = c; +} + +#ifdef MODE_1 +void bobblesort1A(int a[],int n) +{ + bool sorted = false; + A: + sorted = true; + + for(int i = 1 ; i < n ; i++) + { + if(a[i-1] > a[i]) + { + swap(&a[i-1],&a[i]); + + sorted=false; + } + + } + n--; + if(sorted==false) + goto A; +} + +#elif defined MODE_2 +void bobblesort1A(int a[],int n) +{ + bool sorted = false; + sorted = true; + + for(int i = 1 ; i < n ; i++) + { + if(a[i-1] > a[i]) + { + swap(&a[i-1],&a[i]); + + sorted=false; + } + + } + n--; + if(n==1) + return; + + bobblesort1A(a,n); +} +#endif + +int main(){ + init(); + clock_t start_t, end_t; + double total_t; + + #ifdef OUTPUT + printf("Before\n"); + for(int i=0;i +#include +#include +#include + + +class Vec +{ + private: + + int *v; + int LEN; + int USED; + + + public: + + Vec(int len) + { + LEN=len*2; + v=new int[LEN]; + USED=9; + + for(int i=0;i<10;i++) + v[i]=i+1; + + for(int i=0;i<10;i++) + swap(i,rand()%10); + } + + int get(int a) + { + return v[a]; + } + + void put(int a,int value) + { + v[a]=value; + } + + void swap(int a, int b) + { + int temp = v[a]; + v[a] = v[b]; + v[b] = temp; + } + + void expand() + { + LEN=LEN*2; + int *p=new int[LEN]; + + for(int i=0;i<=USED;i++) + p[i]=v[i]; + + delete[] v; + v=p; + } + + void shrink() + { + LEN=LEN>>1; + int *p=new int[LEN]; + + for(int i=0;i<=USED;i++) + p[i]=v[i]; + + delete[] v; + v=p; + } + + int insert(int locate,int value) + { + if(locate<0||locate>USED) + return 1; + + USED++; + if(USED>=LEN) + expand(); + + for(int i=USED;i>locate;i--) + v[i]=v[i-1]; + + v[locate]=value; + + return 0; + } + + int del(int locate,int value) + { + + if(locate<0||((USED-value)<0)||((locate+value-1)>USED)) + return 1; + + USED=USED-value; + + for(int i=locate;i<=USED;i++) + v[i]=v[i+value]; + + if( ( (double)USED/(double)LEN )<=0.3 ) + shrink(); + + return 0; + } + + int find(int value) + { + int i = 0; + for(i;i<=USED;i++) + { + if(v[i]==value) + { + return i; + } + } + + return -1; + } + + void printall() + { + for(int i=0;i +#include +int main() +{ + printf("测试"); + system("pause"); + return 0; +} \ No newline at end of file diff --git a/workspace.code-workspace b/workspace.code-workspace new file mode 100644 index 0000000..61431b4 --- /dev/null +++ b/workspace.code-workspace @@ -0,0 +1,41 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.associations": { + "ctime": "cpp", + "iostream": "cpp", + "new": "cpp" + }, + "files.encoding": "gb2312" + }, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "gcc.exe - 生成和调试活动文件", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "args": [], + "stopAtEntry": false, + "cwd": "C:/Project/mingw64/bin", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "C:\\Project\\mingw64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "为 gdb 启用整齐打印", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: gcc.exe 生成活动文件" + } + ] + } +} \ No newline at end of file