-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceiling.cpp
More file actions
64 lines (41 loc) · 917 Bytes
/
ceiling.cpp
File metadata and controls
64 lines (41 loc) · 917 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<algorithm>
#include<iostream>
#include<bits/stdc++.h>
#include"essentials.cpp"
using namespace std;
float ceiling(float array[],float key,int low, int high){
int med=low+(high-low)/2;
if(array[med]==key){
return array[med+1];}
else if(key>array[high]){
return -1;
}
else if(key<array[low]){
return array[low];
}
else if(key>array[med]){
if(med+1<=high && key<array[med+1]){
return array[med+1];}
else
return ceiling(array,key,med+1,high);
}
else {
cout<<"hi"<<endl;
if(med-1>=low && key>array[med-1]){
return array[med];
}
else{
return ceiling(array,key,low,med-1);
}
}
}
int main(){
// int array[]={1,4,5,6,3,9};
float array[]={1.1,2.3,4.5,5.6,5.7,6.7};
int size=sizeof(array)/sizeof(array[0]);
// print_array(array,size);
int low=0;
int high=size-1;
cout<<ceiling(array,1.1,low,high)<<endl;
return 1;
}