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/d7/d83/trie__tree_8cpp_source.html below:

TheAlgorithms/C++: data_structures/trie_tree.cpp Source File

Go to the documentation of this file. 39 if

(ch >=

'A'

&& ch <=

'Z'

) {

41

}

else if

(ch >=

'a'

&& ch <=

'z'

) {

45

std::cerr <<

"Invalid character present. Exiting..."

;

46

std::exit(EXIT_FAILURE);

56 bool search

(

const

std::shared_ptr<trie>& root,

const

std::string& str,

58 if

(index == str.length()) {

59 if

(!root->isEndofWord) {

68 return search

(root->arr[j], str, index + 1);

77 void insert

(

const

std::string& str) {

78

std::shared_ptr<trie> root(

nullptr

);

80 for

(

const char

& ch : str) {

86

std::shared_ptr<trie> temp(

new trie

());

90

}

else if

(

arr

[j]) {

93

std::shared_ptr<trie> temp(

new trie

());

98

root->isEndofWord =

true

;

107 bool search

(

const

std::string& str,

int

index) {

108 if

(index == str.length()) {

118 return search

(

arr

[j], str, index + 1);

135 if

(index == str.length()) {

167

std::cout << __func__ <<

":"

<< __LINE__

168

<<

"Should not reach this line\n"

;

181

root.insert(

"World"

);

183

assert(!root.search(

"hello"

, 0));

184

std::cout <<

"hello - "

<< root.search(

"hello"

, 0) <<

"\n"

;

186

assert(root.search(

"Hello"

, 0));

187

std::cout <<

"Hello - "

<< root.search(

"Hello"

, 0) <<

"\n"

;

189

assert(!root.search(

"Word"

, 0));

190

std::cout <<

"Word - "

<< root.search(

"Word"

, 0) <<

"\n"

;

192

assert(root.search(

"World"

, 0));

193

std::cout <<

"World - "

<< root.search(

"World"

, 0) <<

"\n"

;

Trie implementation for small-case English alphabets a-z

void insert(const std::string &str)

std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr

Recursive tree nodes as an array of shared-pointers.

bool search(const std::string &str, int index)

static constexpr uint8_t NUM_CHARS

Number of alphabets.

bool isEndofWord

identifier if a node is terminal node

trie()=default

Class default constructor.

bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)

uint8_t char_to_int(const char &ch) const

Convert a character to integer for indexing.

bool deleteString(const std::string &str, int index)

static void test()

Testing function.

int main()

Main function.


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