Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
29 changes: 14 additions & 15 deletions C++/Algorithm/Searching/binarySearchIterative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ int binarysearch(vector < int > & arr, int ele) {
}
return -1;
}

int main() {
vector<int> arr{ 2, 3, 5, 10, 35, 40 }; //sorted array

int element = 10; // element to find

int result = binarysearch(arr, element);

if (result == -1) { // if element not present in array.
cout << "Element is not present in array";
} else {
cout << "Element is present at index " << result;
int main()
{
vector<int> arr{2,3,5,10,35,40}; //sorted array
int element=10; //element to find
int result= binarysearch(arr,element);
if(result==-1) //if element is not present
{
cout<<"Element is not present in array.";
}

return 0;
}
else
{
cout<<"Element is present at index-"<<result;
}
return (0);
}