-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathplaywithsort.cpp
51 lines (41 loc) · 1.51 KB
/
playwithsort.cpp
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
#include "OrderedVector.hpp"
#include "Complex.hpp"
#include <string>
#include <iostream>
#include <algorithm>
#include <ranges>
struct ReverseStringLess {
bool operator() (const std::string &s, const std::string &t) const {
// TODO: compare reversed strings
// hint: you can use:
// - std::views::reverse
// - std::ranges::lexicographical_compare
// or, if your compiler does not support those yet,
// take copies of the strings and reverse them using std::reverse
return s < t;
}
};
int main() {
std::cout << "Integer\n";
OrderedVector<int> v(10);
for (int i = 10; i > 0; i--)
v.add(i);
for (int i = 0; i < 10; i++)
std::cout << v[i] << " ";
std::cout << "\n\n";
std::cout << "String\n";
OrderedVector<std::string> vs(5);
vs.add(std::string("one"));
vs.add(std::string("two"));
vs.add(std::string("three"));
vs.add(std::string("four"));
vs.add(std::string("five"));
for (int i = 0; i < 5; i++)
std::cout << vs[i] << " ";
std::cout << "\n\n";
// TODO: Demonstrate OrderedVector with Complex as element type similar to above
// TODO: Extend OrderedVector to allow to customize the ordering via an additional template paramter.
// Then, demonstrate the new functionality by ordering an OrderedVector<std::string>,
// where the strings are compared starting at their last letters.
// TODO: Order an OrderedVector of Complex based on the Manhattan distance
}