Skip to content

Commit fcdfd94

Browse files
authored
Use range based for loops
1 parent d81209b commit fcdfd94

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: code/search/src/binary_search/binary_search_2.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ using namespace std;
1111

1212
void fill(vector<int> &v)
1313
{
14-
for (std::size_t i = 0; i < v.size(); i++)
15-
v[i] = rand() % 100;
14+
for (auto& elem : v)
15+
elem = rand() % 100;
1616
}
1717

1818
void printarr(vector<int> &v)
1919
{
20-
for (std::size_t i = 0; i < v.size(); i++)
21-
cout << v[i] << " ";
22-
cout << endl;
20+
for (const auto& elem : v)
21+
cout << elem << " ";
22+
cout << "\n";
2323
}
2424

2525
/* Binary search with fewer comparisons */
@@ -49,7 +49,7 @@ int binary_search(vector<int> &v, int key)
4949
int main()
5050
{
5151
int size;
52-
cout << "Set array size:";
52+
cout << "Enter the array size:";
5353
cin >> size;
5454

5555
vector<int> v(size);

0 commit comments

Comments
 (0)