Skip to content

Commit 83b9e10

Browse files
committed
fixes.
1 parent a168ad8 commit 83b9e10

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

strings/duval.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
* @author [Amine Ghoussaini](https://github.com/aminegh20)
2727
*/
2828

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
3636

37+
/**
38+
* @brief string manipulation algorithms
39+
* @namespace
40+
*/
3741
namespace string {
3842
/**
3943
* @brief Find the lexicographically smallest cyclic shift of a sequence.
@@ -48,7 +52,7 @@ size_t duval(const T& s) {
4852
while (i < n) {
4953
ans = i;
5054
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]) {
5256
if (s[k % n] < s[j % n]) {
5357
k = i;
5458
} else {
@@ -66,6 +70,10 @@ size_t duval(const T& s) {
6670

6771
} // namespace string
6872

73+
/**
74+
* @brief self test implementation
75+
* returns void
76+
*/
6977
static void test() {
7078
using namespace string;
7179

@@ -89,10 +97,18 @@ static void test() {
8997
std::deque<char> d = {'a', 'z', 'c', 'a', 'b'};
9098
assert(duval(d) == 3);
9199

100+
// Test 6
101+
std::string s3;
102+
assert(duval(s3) == 0);
103+
92104
std::cout << "All tests passed!" << std::endl;
93105
}
94106

107+
/**
108+
* @brief main function
109+
* @returns 0 on exit
110+
*/
95111
int main() {
96-
test();
112+
test(); // run self test implementations
97113
return 0;
98114
}

0 commit comments

Comments
 (0)