26
26
* @author [Amine Ghoussaini](https://github.com/aminegh20)
27
27
*/
28
28
29
- #include < array> // /< for std::array
30
- #include < cassert> // /< for assert
31
- #include < cstddef> // /< for std::size_t
32
- #include < deque> // /< for std::deque
33
- #include < iostream> // /< for std::cout and std::endl
34
- #include < string> // /< for std::string
35
- #include < vector> // /< for std::vector
29
+ #include < array> // / for std::array
30
+ #include < cassert> // / for assert
31
+ #include < cstddef> // / for std::size_t
32
+ #include < deque> // / for std::deque
33
+ #include < iostream> // / for std::cout and std::endl
34
+ #include < string> // / for std::string
35
+ #include < vector> // / for std::vector
36
36
37
+ /* *
38
+ * @brief string manipulation algorithms
39
+ * @namespace
40
+ */
37
41
namespace string {
38
42
/* *
39
43
* @brief Find the lexicographically smallest cyclic shift of a sequence.
@@ -48,7 +52,7 @@ size_t duval(const T& s) {
48
52
while (i < n) {
49
53
ans = i;
50
54
size_t j = i + 1 , k = i;
51
- while (j < n + n && s[j % n] >= s[k % n]) {
55
+ while (j < ( n + n) && s[j % n] >= s[k % n]) {
52
56
if (s[k % n] < s[j % n]) {
53
57
k = i;
54
58
} else {
@@ -66,6 +70,10 @@ size_t duval(const T& s) {
66
70
67
71
} // namespace string
68
72
73
+ /* *
74
+ * @brief self test implementation
75
+ * returns void
76
+ */
69
77
static void test () {
70
78
using namespace string ;
71
79
@@ -89,10 +97,18 @@ static void test() {
89
97
std::deque<char > d = {' a' , ' z' , ' c' , ' a' , ' b' };
90
98
assert (duval (d) == 3 );
91
99
100
+ // Test 6
101
+ std::string s3;
102
+ assert (duval (s3) == 0 );
103
+
92
104
std::cout << " All tests passed!" << std::endl;
93
105
}
94
106
107
+ /* *
108
+ * @brief main function
109
+ * @returns 0 on exit
110
+ */
95
111
int main () {
96
- test ();
112
+ test (); // run self test implementations
97
113
return 0 ;
98
114
}
0 commit comments