Advertisement
Guest User

Group 1 Orderset.cpp

a guest
May 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include<cstdio>
  2. #include<sstream>
  3. #include<cstdlib>
  4. #include<cctype>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<set>
  8. #include<queue>
  9. #include<stack>
  10. #include<list>
  11. #include<iostream>
  12. #include<fstream>
  13. #include<numeric>
  14. #include<string>
  15. #include<vector>
  16. #include<cstring>
  17. #include<map>
  18. #include<iterator>
  19. #include <iomanip>
  20.  
  21. using namespace std;
  22.  
  23. // #include <ext/pb_ds/assoc_container.hpp>
  24. // #include <ext/pb_ds/tree_policy.hpp>
  25. // using namespace __gnu_pbds;
  26. // typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  27.  
  28.  
  29.  
  30.  
  31.  
  32. class Trie
  33. {
  34.     const static int mx=10;
  35.     struct node
  36.     {
  37.         bool endmark;
  38.         node *next[mx];
  39.         node()
  40.         {
  41.             endmark=false;
  42.             for(int i=0;i<mx;i++)next[i]=NULL;
  43.         }
  44.     }*root;
  45.  
  46.     void del(node* cur)
  47.     {
  48.         for (int i = 0; i < mx; i++)
  49.             if (cur->next[i])
  50.                 del(cur->next[i]);
  51.         delete (cur);
  52.     }
  53.  public:
  54.     Trie()
  55.     {
  56.         root=new node();
  57.     }
  58.     ~Trie()
  59.     {
  60.         del(root);
  61.     }
  62.     void insert(string s)
  63.     {
  64.         node *curr=root;
  65.         for(int i=0;i<s.size();i++)
  66.         {
  67.             int k=s[i]-'0';
  68.             if(curr->next[k]==NULL)
  69.                 curr->next[k]=new node();
  70.             curr=curr->next[k];
  71.         }
  72.         curr->endmark=true;
  73.     }
  74.     bool search(string s)
  75.     {
  76.         node *curr=root;
  77.         for(int i=0;i<s.size();i++)
  78.         {
  79.             int k=s[i]-'0';
  80.             if(curr->next[k]==NULL)
  81.                 return false;
  82.             curr=curr->next[k];
  83.         }
  84.         return curr->endmark;
  85.     }
  86. };
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. int main(int argc, char const *argv[])
  96. {
  97.    
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement