Skip to content

Commit aa72edc

Browse files
committed
Indentations improved
1 parent f3d2c50 commit aa72edc

27 files changed

+125
-130
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
# Amazing-STL-Algoritms
2-
<h1 style="font-style: italic;">C++ is all about control</h1>
3-
<blockquote>
4-
Algorithms are beautifull
5-
</blockquote>

accumulate.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 2, 2, -2, 4, 0 };
10-
int total = accumulate(begin(v), end(v), 0);
11-
cout << total << endl;
12-
total = accumulate(begin(v), end(v), 0,
13-
[](int total, int i) {if(i % 2 == 0) return total + i; return total;});
14-
cout << total;
15-
return 0;
9+
vector<int> v{ 2, 7, 2, 2, -2, 4, 0 };
10+
int total = accumulate(begin(v), end(v), 0);
11+
cout << total << endl;
12+
total = accumulate(begin(v), end(v), 0,
13+
[](int total, int i) {if(i % 2 == 0) return total + i; return total;});
14+
cout << total;
15+
return 0;
1616
}

adjacent_find.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, 2, 4, 0 };
10-
auto result = adjacent_find(begin(v), end(v));
11-
cout << *result << endl;
12-
advance(result, 3);
13-
cout << *result << endl;
14-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, 2, 4, 0 };
10+
auto result = adjacent_find(begin(v), end(v));
11+
cout << *result << endl;
12+
advance(result, 3);
13+
cout << *result << endl;
14+
return 0;
1515
}

all_of.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
bool result = all_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11-
cout << result << endl;
12-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
bool result = all_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11+
cout << result << endl;
12+
return 0;
1313
}

any_of.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
bool result = any_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11-
cout << result << endl;
12-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
bool result = any_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11+
cout << result << endl;
12+
return 0;
1313
}

copy.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ int main()
1010
vector<int> v(source.size());
1111
copy(begin(source), end(source), begin(v));
1212
for(auto elem : v)
13-
{
14-
cout << elem << " ";
15-
}
13+
{
14+
cout << elem << " ";
15+
}
1616
return 0;
1717
}

copy_backward.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ int main()
1010
vector<int> v(source.size());
1111
copy_backward(begin(source), end(source), end(v));
1212
for(auto elem : v)
13-
{
14-
cout << elem << " ";
15-
}
13+
{
14+
cout << elem << " ";
15+
}
1616
return 0;
1717
}

copy_if.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> source{ 4, 3, 2, 0, 15, 2, 100, -5, 1000 };
9+
vector<int> source{ 4, 3, 2, 0, 15, 2, 100, -5, 1000 };
1010
vector<int> v(source.size());
1111
copy_if(begin(source), end(source), begin(v), [](int elem) {return elem % 2 == 0;});
1212
for(auto elem : v)
13-
{
14-
cout << elem << " ";
15-
}
13+
{
14+
cout << elem << " ";
15+
}
1616
return 0;
1717
}

copy_n.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> source{ 4, 3, 2, 0, 15, 2, 100, -5, 1000 };
9+
vector<int> source{ 4, 3, 2, 0, 15, 2, 100, -5, 1000 };
1010
vector<int> v(source.size());
1111
int req = 4;
1212
copy_n(begin(source), req, begin(v));
1313
for(auto elem : v)
14-
{
15-
cout << elem << " ";
16-
}
14+
{
15+
cout << elem << " ";
16+
}
1717
return 0;
1818
}

count.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int target = v[0];
11-
int result = count(begin(v), end(v), target);
12-
//or
13-
//int result = count(v.begin(), v.end(), target);
14-
cout << result << endl;
15-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int target = v[0];
11+
int result = count(begin(v), end(v), target);
12+
//or
13+
//int result = count(v.begin(), v.end(), target);
14+
cout << result << endl;
15+
return 0;
1616
}

count_if.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int result = count_if(begin(v), end(v), [](auto elem) { return elem > 0;});
11-
cout << result << endl;
12-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int result = count_if(begin(v), end(v), [](auto elem) { return elem > 0;});
11+
cout << result << endl;
12+
return 0;
1313
}

equal.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v1{ 2, 7, 1, 2, -2, 4, 0 };
10-
vector<int> v2{ 1, 23, 45, 1, 2, 4, 0 };
11-
bool same = equal(begin(v1), end(v1), begin(v2), end(v2));
12-
cout << same << endl;
13-
return 0;
9+
vector<int> v1{ 2, 7, 1, 2, -2, 4, 0 };
10+
vector<int> v2{ 1, 23, 45, 1, 2, 4, 0 };
11+
bool same = equal(begin(v1), end(v1), begin(v2), end(v2));
12+
cout << same << endl;
13+
return 0;
1414
}

find.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int target = v[5];
11-
auto result = find(begin(v), end(v), target);
12-
cout << *result << endl;
13-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int target = v[5];
11+
auto result = find(begin(v), end(v), target);
12+
cout << *result << endl;
13+
return 0;
1414
}

find_end.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
vector<int> subVec{ -2, 4 };
11-
auto result = find_end(begin(v), end(v), begin(subVec), end(subVec));
12-
// first element of subVec
13-
cout << *result << endl;
14-
advance(result, 1);
15-
// last element of subVec
16-
cout << *result << endl;
17-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
vector<int> subVec{ -2, 4 };
11+
auto result = find_end(begin(v), end(v), begin(subVec), end(subVec));
12+
// first element of subVec
13+
cout << *result << endl;
14+
advance(result, 1);
15+
// last element of subVec
16+
cout << *result << endl;
17+
return 0;
1818
}

find_first_of.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
vector<int> primes{ 3, 5, 7 };
11-
auto result = find_first_of(begin(v), end(v), begin(primes), end(primes));
12-
cout << *result << endl;
13-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
vector<int> primes{ 3, 5, 7 };
11+
auto result = find_first_of(begin(v), end(v), begin(primes), end(primes));
12+
cout << *result << endl;
13+
return 0;
1414
}

find_if.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int target = v[0];
11-
auto result = find_if(begin(v), end(v), [target](auto elem) {return elem == target;} );
12-
cout << *result << endl;
13-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int target = v[0];
11+
auto result = find_if(begin(v), end(v), [target](auto elem) {return elem == target;} );
12+
cout << *result << endl;
13+
return 0;
1414
}

find_if_not.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int target = v[0];
11-
auto result = find_if_not(begin(v), end(v), [target](auto elem) {return elem == target;} );
12-
cout << *result << endl;
13-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int target = v[0];
11+
auto result = find_if_not(begin(v), end(v), [target](auto elem) {return elem == target;} );
12+
cout << *result << endl;
13+
return 0;
1414
}

for_each.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 2, 2, -2, 4, 0 };
10-
for_each(begin(v), end(v), [](int& elem) {return elem = 1;});
11-
int total = accumulate(begin(v), end(v), 0);
12-
cout << total;
13-
return 0;
9+
vector<int> v{ 2, 7, 2, 2, -2, 4, 0 };
10+
for_each(begin(v), end(v), [](int& elem) {return elem = 1;});
11+
int total = accumulate(begin(v), end(v), 0);
12+
cout << total;
13+
return 0;
1414
}

is_sorted_until.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 3, 4, -5, 6, 17 };
10-
auto result = is_sorted_until(begin(v), begin(v) + 2);
9+
vector<int> v{ 2, 3, 4, -5, 6, 17 };
10+
auto result = is_sorted_until(begin(v), begin(v) + 2);
1111
cout << *result;
1212
return 0;
1313
}

mismatch.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v1{ 2, 7, 1, 2, -2, 4, 0 };
10-
vector<int> v2{ 2, 7, 2, 2, -2, 4, 0 };
11-
auto diff = mismatch(begin(v1), end(v1), begin(v2));
12-
cout << *diff.first << endl;
13-
cout << *diff.second << endl;
14-
return 0;
9+
vector<int> v1{ 2, 7, 1, 2, -2, 4, 0 };
10+
vector<int> v2{ 2, 7, 2, 2, -2, 4, 0 };
11+
auto diff = mismatch(begin(v1), end(v1), begin(v2));
12+
cout << *diff.first << endl;
13+
cout << *diff.second << endl;
14+
return 0;
1515
}

none_of.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
bool result = none_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11-
cout << result << endl;
12-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
bool result = none_of(begin(v), end(v), [](auto elem) {return elem > -4;});
11+
cout << result << endl;
12+
return 0;
1313
}

nth_element.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ int main()
99
vector<int> v{ 4, 3, 2, 0, 15, 2, 100, -5, 1000 };
1010
nth_element(begin(v), begin(v) + 6, end(v));
1111
for(auto elem : v)
12-
{
13-
cout << elem << " ";
14-
}
12+
{
13+
cout << elem << " ";
14+
}
1515
return 0;
1616
}

partial_sort.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 45, 2, 3, 4, -5, 6, 17 };
10-
int target = v[3];
9+
vector<int> v{ 45, 2, 3, 4, -5, 6, 17 };
10+
int target = v[3];
1111
partial_sort(begin(v), find(begin(v), end(v), target), end(v));
1212
for(auto elem : v)
1313
{
14-
cout << elem << " ";
14+
cout << elem << " ";
1515
}
1616
return 0;
1717
}

partial_sort_copy.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ using namespace std;
66

77
void print(vector<int> v)
88
{
9-
for(auto elem : v)
10-
{
11-
cout << elem << " ";
12-
}
13-
cout << "\n";
9+
for(auto elem : v)
10+
{
11+
cout << elem << " ";
12+
}
13+
cout << "\n";
1414
}
1515

1616
int main()

search.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
vector<int> subVec{ 2, -2, 4, 0 };
11-
auto result = search(begin(v), end(v), begin(subVec), end(subVec));
12-
// first element of subVec
13-
cout << *result << endl;
14-
advance(result, 3);
15-
// last element of subVec
16-
cout << *result << endl;
17-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
vector<int> subVec{ 2, -2, 4, 0 };
11+
auto result = search(begin(v), end(v), begin(subVec), end(subVec));
12+
// first element of subVec
13+
cout << *result << endl;
14+
advance(result, 3);
15+
// last element of subVec
16+
cout << *result << endl;
17+
return 0;
1818
}

search_n.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ using namespace std;
66

77
int main()
88
{
9-
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10-
int target = v[5];
11-
int repeat = 1;
12-
auto result = search_n(begin(v), end(v), repeat, target);
13-
cout << *result << endl;
14-
return 0;
9+
vector<int> v{ 2, 7, 1, 2, -2, 4, 0 };
10+
int target = v[5];
11+
int repeat = 1;
12+
auto result = search_n(begin(v), end(v), repeat, target);
13+
cout << *result << endl;
14+
return 0;
1515
}

0 commit comments

Comments
 (0)