We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d81209b commit fcdfd94Copy full SHA for fcdfd94
code/search/src/binary_search/binary_search_2.cpp
@@ -11,15 +11,15 @@ using namespace std;
11
12
void fill(vector<int> &v)
13
{
14
- for (std::size_t i = 0; i < v.size(); i++)
15
- v[i] = rand() % 100;
+ for (auto& elem : v)
+ elem = rand() % 100;
16
}
17
18
void printarr(vector<int> &v)
19
20
21
- cout << v[i] << " ";
22
- cout << endl;
+ for (const auto& elem : v)
+ cout << elem << " ";
+ cout << "\n";
23
24
25
/* Binary search with fewer comparisons */
@@ -49,7 +49,7 @@ int binary_search(vector<int> &v, int key)
49
int main()
50
51
int size;
52
- cout << "Set array size:";
+ cout << "Enter the array size:";
53
cin >> size;
54
55
vector<int> v(size);
0 commit comments