Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
// 2) WAP to implement binary search #include
using namespace std; int main(){ cout<<"Enter the size of the sorted array: "; int n; cin>>n; int arr[n]; cout<<"Enter the array elements: "; for(int i=0;i
>arr[i]; } cout<<"Enter the element to be searched: "; int element; cin>>element; int index=-1; int low=0,high=n-1; while(low<=high){ int mid=(low+high)/2; if(arr[mid]==element){ index=mid; break; } else if(arr[mid]>element) high=mid-1; else low=mid+1; } if(index!=-1){ cout<<"Element found at index: "<
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)