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/d5/d8a/trie__using__hashmap_8cpp.html below:

TheAlgorithms/C++: data_structures/trie_using_hashmap.cpp File Reference

Self-test implementations.

221 {

223

224

226

obj.

insert

(

"abscond"

);

232

obj.

insert

(

"approach"

);

237

238

assert(!obj.

search

(

"appy"

));

239 std::cout << "appy is not a word in trie" << std::endl;

240

241

assert(!obj.

search

(

"car"

));

242 std::cout << "car is not a word in trie" << std::endl;

243

assert(obj.

search

(

"app"

));

244

assert(obj.

search

(

"apple"

));

245

assert(obj.

search

(

"apples"

));

246

assert(obj.

search

(

"apps"

));

247

assert(obj.

search

(

"apen"

));

248

assert(obj.

search

(

"approach"

));

249

assert(obj.

search

(

"about"

));

250

assert(obj.

search

(

"abscond"

));

251

assert(obj.

search

(

"bus"

));

252

assert(obj.

search

(

"buses"

));

253

assert(obj.

search

(

"Bounce"

));

254

assert(obj.

search

(

"Apple"

));

255

256 std::cout << "All the Inserted words are present in the trie" << std::endl;

257

258

274

276

277 std::cout << "All the tests passed for startwith method" << std::endl;

278

279

280

281

std::vector<std::string> pred_words = obj.

predict_words

(

"a"

);

282

284 std::cout << str << std::endl;

285 }

286 assert(pred_words.size() == 8);

287 std::cout << "Returned all words that start with prefix a " << std::endl;

289

290 for (const std::string& str : pred_words) {

291 std::cout << str << std::endl;

292 }

293

294 assert(pred_words.size() == 5);

295 std::cout << "Returned all words that start with prefix app " << std::endl;

297

298 for (const std::string& str : pred_words) {

299 std::cout << str << std::endl;

300 }

301

302 assert(pred_words.size() == 1);

303 std::cout << "Returned all words that start with prefix A " << std::endl;

305

306 for (const std::string& str : pred_words) {

307 std::cout << str << std::endl;

308 }

309

310 assert(pred_words.size() == 2);

311 std::cout << "Returned all words that start with prefix bu " << std::endl;

312

313

314

316

assert(!obj.

search

(

"app"

));

317 std::cout << "word app is deleted sucessful" << std::endl;

318

320 for (const std::string& str : pred_words) {

321 std::cout << str << std::endl;

322 }

323 assert(pred_words.size() == 4);

324 std::cout << "app is deleted sucessful" << std::endl;

325

326

327

331

332 assert(pred_words.size() == 0);

333 std::cout << "No word starts with prefix h in trie" << std::endl;

334

335 std::cout << "All tests passed" << std::endl;

336}

Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t...

void insert(const std::string &word)

insert the string into the trie

void delete_word(std::string word)

delete a word/string from a trie

bool search(const std::string &word)

search a word/string inside the trie

std::vector< std::string > predict_words(const std::string &prefix)

predict/recommend a word that starts with a given prefix

bool startwith(const std::string &prefix)

search a word/string that starts with a given prefix


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