Advertisement
tinyevil

Untitled

Jan 8th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. generic[K, C:Comparator[K]]
  2. struct Tree{
  3.     ...
  4. }
  5.  
  6. implementation Tree{
  7.  
  8.     generic[S]
  9.     method find(Self self, S key): bool
  10.     where Comparator[S].compare(K,S)
  11.     {
  12.         var node = self.root;
  13.         while (node != null) {
  14.             switch(self.c.compare(node.key, key)){
  15.             case GT: node = node.right;
  16.             case LT: node = node.left;
  17.             case EQ: return true;
  18.             }
  19.         }
  20.         return false;
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement