Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a dictionary by using Trie . Requirement: a. Complete trie.h, trie.cpp, and client1.cpp. client1 #include #include trie.h using namespace std; int main() { Trie

Implement a dictionary by using Trie . Requirement: a. Complete trie.h, trie.cpp, and client1.cpp.

client1

#include #include "trie.h"

using namespace std;

int main() { Trie vocabulary; cout << "Type '0'--quit; '1'--add a word; '2'--search a word; '3'--search prefix: "; int choice; cin >> choice; while(choice) { if(choice == 1) { cout << "Add to the vocabulary this word: "; string word; cin >> word; vocabulary.add(word); } else if(choice == 2) { cout << "Search this word: "; string key; cin >> key; if(vocabulary.contains(key)) cout << key << " exists!" << endl; else cout << key << " does not exists." << endl; } else if(choice == 3) { cout << "Search this prefix: "; string key; cin >> key; if(vocabulary.isPrefix(key)) cout << key << " is a prefix." << endl; else cout << key << " is not a prefix." << endl; } else { cout << "Input incorrect. Try again." << endl; } cout << "Type '0'--quit; '1'--add a word; '2'--search a word; '3'--search prefix: "; cin >> choice; } return 0; }

-------------------------------------------------------------------------------------------------------------------

trie.h

#ifndef TRIE_H #define TRIE_H

#define MAX_CHAR 256

class Node { private: Node *children[MAX_CHAR]; bool bisEnd; public: Node(); bool isEnd(); void insert(string suffix); Node* search(string pat); };

class Trie { private: Node root; public: void add(string word); bool contains(string pat); bool isPrefix(string pat); }; #endif

--------------------------------------------------------------------------------------------

trie.cpp

#include #include "trie.h"

using namespace std;

/* add your Trie implementation here */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

Students also viewed these Databases questions

Question

What is the typical attribute of interest in an MUS application?

Answered: 1 week ago

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago