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