Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #include <iomanip>
- using namespace std;
- // #include <ext/pb_ds/assoc_container.hpp>
- // #include <ext/pb_ds/tree_policy.hpp>
- // using namespace __gnu_pbds;
- // typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- class Trie
- {
- const static int mx=10;
- struct node
- {
- bool endmark;
- node *next[mx];
- node()
- {
- endmark=false;
- for(int i=0;i<mx;i++)next[i]=NULL;
- }
- }*root;
- void del(node* cur)
- {
- for (int i = 0; i < mx; i++)
- if (cur->next[i])
- del(cur->next[i]);
- delete (cur);
- }
- public:
- Trie()
- {
- root=new node();
- }
- ~Trie()
- {
- del(root);
- }
- void insert(string s)
- {
- node *curr=root;
- for(int i=0;i<s.size();i++)
- {
- int k=s[i]-'0';
- if(curr->next[k]==NULL)
- curr->next[k]=new node();
- curr=curr->next[k];
- }
- curr->endmark=true;
- }
- bool search(string s)
- {
- node *curr=root;
- for(int i=0;i<s.size();i++)
- {
- int k=s[i]-'0';
- if(curr->next[k]==NULL)
- return false;
- curr=curr->next[k];
- }
- return curr->endmark;
- }
- };
- int main(int argc, char const *argv[])
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement