From 5baa55d02517b4812e7331578548de8cef084df1 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Sun, 8 Sep 2024 10:57:25 +0200 Subject: [PATCH] update --- .vscode/launch.json | 30 ++++++++++++++++++++++++++++++ .vscode/tasks.json | 28 ++++++++++++++++++++++++++++ c++/Makefile | 3 +++ c++/libhelper.c | 25 +++++++++++++++++++++++++ c++/libhelper.h | 8 ++++++++ 5 files changed, 94 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 c++/Makefile create mode 100644 c++/libhelper.c create mode 100644 c++/libhelper.h diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..86b29fb --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "enter program name, for example ${workspaceFolder}/a.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/path/to/gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a0b9074 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:\\MyPrograms\\msys2\\ucrt64\\bin\\gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/c++/Makefile b/c++/Makefile new file mode 100644 index 0000000..291c8d2 --- /dev/null +++ b/c++/Makefile @@ -0,0 +1,3 @@ +all: + #gcc -o libhelper.so -shared -fPIC libhelper.c -Ofast + gcc -shared -o libhelper.dylib -arch x86_64 libhelper.c \ No newline at end of file diff --git a/c++/libhelper.c b/c++/libhelper.c new file mode 100644 index 0000000..90f2e59 --- /dev/null +++ b/c++/libhelper.c @@ -0,0 +1,25 @@ +#ifndef LIBHELPER_C +#define LIBHELPER_C + +#include "libhelper.h" + +#include + + +// Binary search function to find the index where 'x' should be inserted in the sorted array 'arr' +int searchSorted(float arr[], int n, float x) { + int left = 0; + int right = n; + while (left < right) { + int mid = left + (right - left) / 2; + if (arr[mid] < x) { + left = mid + 1; + } else { + right = mid; + } + } + return left; +} + + +#endif \ No newline at end of file diff --git a/c++/libhelper.h b/c++/libhelper.h new file mode 100644 index 0000000..27539dd --- /dev/null +++ b/c++/libhelper.h @@ -0,0 +1,8 @@ +#ifndef LIBHELPER_H +#define LIBHELPER_H + +// #include + +int searchSorted(float arr[], int n, float x); + +#endif \ No newline at end of file