-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinerpolation_string.cpp
More file actions
30 lines (30 loc) · 772 Bytes
/
inerpolation_string.cpp
File metadata and controls
30 lines (30 loc) · 772 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
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
string st1 = "ROHIT";
string arr[] = {"AMAR" , "AMARJEET", "BHEEM" , "BIMAL" , "CHAND" ,"CHARU", "DEV" , "DHAWAN","ESHA","GANESH" , "ROHIT" , "ZAHID"};
int l = (int)(arr[0].at(0));
int h = (int)(arr[11].at(0));
int x = (int)(st1.at(0));
int low =0 , hi = 11 , pos=0;
while(x<=h && x >=l && l<h)
{
pos = low + ((hi-low) * (x-l)) /(h-l);
if(arr[pos] == st1)
{
cout<<"\nFound at pos:- "<<(pos+1);
break;
}
else
{
if(arr[pos] > st1)
hi = pos-1;
else
low = pos +1;
}
}
return 0 ;
}