Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhang02 committed Sep 8, 2024
1 parent 9751d0c commit 5baa55d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions c++/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
#gcc -o libhelper.so -shared -fPIC libhelper.c -Ofast
gcc -shared -o libhelper.dylib -arch x86_64 libhelper.c
25 changes: 25 additions & 0 deletions c++/libhelper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef LIBHELPER_C
#define LIBHELPER_C

#include "libhelper.h"

#include <stdio.h>


// 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
8 changes: 8 additions & 0 deletions c++/libhelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef LIBHELPER_H
#define LIBHELPER_H

// #include <stdio.h>

int searchSorted(float arr[], int n, float x);

#endif

0 comments on commit 5baa55d

Please sign in to comment.