-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearching.cpp
More file actions
41 lines (37 loc) · 722 Bytes
/
Copy pathsearching.cpp
File metadata and controls
41 lines (37 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<bits/stdc++.h>
using namespace std;
template<typename T>
void show(T arr[],int size)
{
for (int i = 0; i < size; i++)
{
cout<<" "<<arr[i];
}
cout<<endl;
}
int main()
{
int a[]={1,4,2,3,9,5,6,10};
int s=sizeof(a)/sizeof(a[0]);
cout<<"Before sorting\n";
show(a,s);
cout<<"After sorting\n";
sort(a,a+s);
show(a,s);
lable:
int val;
cout<<"Enter value what u want to search"<<endl;
cin>>val;
if(binary_search(a,a+s,val))
cout<<val<<" is present in array"<<endl;
else
cout<<val<<" is not present in array"<<endl;
cout<<"Do u want to search again ....."<<endl;
char ans;
cin>>ans;
if( ans=='y'||ans=='Y')
goto lable;
else
exit;
return 0;
}