diff options
author | Oskar <[email protected]> | 2024-08-11 17:30:28 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-11 17:30:28 +0200 |
commit | b45c0d29ee690c8b436a33581d3b108e6064b5a7 (patch) | |
tree | 90b0df74cb9be982d35b3287f105c2e67f117ebb /3p26.cpp | |
parent | c6a3ec820eeb105752b833c9f5e44f0244a41c6d (diff) |
more confusion
Diffstat (limited to '3p26.cpp')
-rw-r--r-- | 3p26.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/3p26.cpp b/3p26.cpp new file mode 100644 index 0000000..3535b19 --- /dev/null +++ b/3p26.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <vector> +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.26 + * + * We cannot use '+' to add 2 iterators + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +using std::vector; +int main () { + + vector<int> in = {1, 4, 23, 35, 36, 111, 122, 135, 239, 345, 365, 399, 401, 477, 480, 592, 728, 777, 824, 928, 983, 1002, 1023, 1209}; + int sought = 0; + for(auto vt : in) { + cout << vt << " "; + } + + cout << endl; + if(cin >> sought) { + } else { + return -1; + } + + auto beg = in.begin(), end = in.end(); + auto mid = in.begin() + (end - beg)/2; // 12 + while (mid != end && *mid != sought) { + if (sought < *mid) { + end = mid; + } else { + beg = mid + 1; + } + + cout << *mid << endl; + mid = beg + (end - beg)/2; + } + + if(mid != end) { + cout << "found: " << *mid << endl; + } else { + cout << "could not find: " << sought << endl; + } + + return 0; +} |