dsalglib
1.0.0
dsalglib is a ready to use data structures and algorithms library written in C++ . Object Oriented Template implementations are written.
Main Page
Namespaces
Classes
Files
File List
File Members
source
include
binarysearch.h
Go to the documentation of this file.
1
//
2
// Created by moghya_s on 10/2/2016.
3
//
4
5
#ifndef DSALGLIB_BINARYSEARCH_H
6
#define DSALGLIB_BINARYSEARCH_H
7
8
#include "
array.h
"
9
namespace
dsa
10
{
11
template
<
typename
type>
12
long
long
int
binarysearch
(
array<type>
arr,
long
long
int
start,
long
long
int
end,type param)
13
{
14
if
(start<=end)
15
{
16
long
long
int
mid=(start+end)/2;
17
if
(arr[mid]<param)
18
return
binarysearch
(arr,mid+1,end,param);
19
else
20
if
(param<arr[mid])
21
return
binarysearch
(arr,start,mid-1,param);
22
else
23
return
mid;
24
}
25
else
26
{
27
return
-1;
28
}
29
}
30
}
31
#endif //DSALGLIB_BINARYSEARCH_H
dsa
Definition:
alginc.h:12
dsa::binarysearch
long long int binarysearch(array< type > arr, long long int start, long long int end, type param)
Definition:
binarysearch.h:12
array.h
dsa::array
Definition:
array.h:10
Generated by
1.8.11