Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <map>
- using namespace std;
- struct Node
- {
- string word;
- int counter;
- Node* left;
- Node* right;
- };
- class WordTree
- {
- Node* head;
- void add_method(const string& _Word, Node*& _Node)
- {
- if (_Node == nullptr)
- {
- _Node = new Node;
- _Node->word = _Word;
- _Node->counter = 1;
- _Node->left = _Node->right = nullptr;
- }
- else
- {
- if (_Node->word > _Word)
- add_method(_Word, _Node->right);
- else if (_Node->word < _Word)
- add_method(_Word, _Node->left);
- else
- _Node->counter++;
- }
- }
- bool is_found_method(const string& _Word, Node* _Node)
- {
- if (_Node == nullptr)
- return false;
- if (_Node->word == _Word)
- return true;
- else
- {
- if (_Node->word > _Word)
- is_found_method(_Word, _Node->right);
- else if (_Node->word < _Word)
- is_found_method(_Word, _Node->left);
- }
- };
- public:
- WordTree()
- {
- head = nullptr;
- }
- void add(const string& _Word)
- {
- add_method(_Word, head);
- }
- bool is_found(const string& _Word)
- {
- return is_found_method(_Word, head);
- }
- };
- int main()
- {
- WordTree a;
- ifstream input("input.txt");
- ifstream addition("compare_with.txt");
- if (!input.is_open() || !addition.is_open())
- return 0;
- while(!input.eof())
- {
- string tmp;
- getline(input, tmp);
- a.add(tmp);
- }
- input.close();
- map<string,int> compare_with;
- while(!addition.eof())
- {
- string tmp;
- getline(input, tmp);
- compare_with[tmp]++;
- }
- addition.close();
- ofstream output("output.txt");
- for(map<string,int>::iterator it = compare_with.begin(); it!= compare_with.end(); ++it)
- {
- if(a.is_found(it->first))
- // Delete function
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement