A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/db/d09/duval_8cpp_source.html below:

TheAlgorithms/C++: strings/duval.cpp Source File

Go to the documentation of this file. 51 size_t

i = 0, ans = 0;

54 size_t

j = i + 1, k = i;

55 while

(j < (n + n) && s[j % n] >= s[k % n]) {

56 if

(s[k % n] < s[j % n]) {

81

std::string s1 =

"abcab"

;

82

assert(

duval

(s1) == 3);

85

std::string s2 =

"011100"

;

86

assert(

duval

(s2) == 4);

89

std::vector<int> v = {5, 2, 1, 3, 4};

90

assert(

duval

(v) == 2);

93

std::array<int, 5> a = {1, 2, 3, 4, 5};

94

assert(

duval

(a) == 0);

97

std::deque<char> d = {

'a'

,

'z'

,

'c'

,

'a'

,

'b'

};

98

assert(

duval

(d) == 3);

102

assert(

duval

(s3) == 0);

105

std::vector<int> v2 = {5, 2, 1, 3, -4};

106

assert(

duval

(v2) == 4);

108

std::cout <<

"All tests passed!"

<< std::endl;

static void test()

self test implementation returns void

string manipulation algorithms

size_t duval(const T &s)

Find the lexicographically smallest cyclic shift of a sequence.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4