Advertisement
gracefu

Untitled

Oct 10th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2.  
  3. // Wikipedia: https://en.wikipedia.org/wiki/AVL_tree
  4. // This datastructure makes a slight modification to the AVL Tree.
  5. // By keeping track of the number of nodes of the subtree rooted at each node,
  6. // we can quickly find the index of a certain node by adding up all the counts
  7. // left of that particular node, and vice versa.
  8.  
  9. // As is, it's pretty useless since it only stores the key and no data.
  10. // That's cause I'm writing this for a silly programming puzzle, not for actual use.
  11. class FastIndexTree {
  12. FastIndexTreeNode root;
  13. }
  14.  
  15. class FastIndexTreeNode {
  16. FastIndexTreeNode *left;
  17. FastIndexTreeNode *right;
  18. int count;
  19. int key;
  20. int balance; // value in {-1, 0, 1}, see Wikipedia
  21.  
  22. // Inserts a node and returns the change in height
  23. int insert(FastIndexTreeNode *node);
  24. // Removes a node and returns the change in height
  25. int remove(FastIndexTreeNode *node);
  26. // Finds the index of a particular value.
  27. int find(int key);
  28. // Finds the node containing a particular value.
  29. FastIndexTreeNode *search(int key);
  30. // Finds the node at a particular index.
  31. FastIndexTreeNode *at(int index);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement