Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. // As usual, you can add new functions and member variables
  2. // in this file, but don't delete what's already declared.
  3. #pragma once
  4.  
  5. #include <iostream>
  6. #include <queue>
  7. #include <stack>
  8.  
  9. class AVLTree
  10. {
  11. private:
  12. struct Node
  13. {
  14. int Data;
  15. Node* Left;
  16. Node* Right;
  17. Node* Parent;
  18.  
  19. Node(int dataValue, Node* parent);
  20. bool DeleteChild(Node* child);
  21. bool ReplaceAndDeleteChild(Node* child, Node* newChild);
  22. };
  23.  
  24. // Pointer to the root node of the binary search tree
  25. // If this is null it implies that the tree is empty
  26. Node* m_root;
  27.  
  28. void AddAllNodesOnLevel(int level, std::queue<Node*>& theQ);
  29.  
  30. static int CountDigits(int decimalValue);
  31.  
  32. int CountLevels(Node* n);
  33.  
  34. void DeleteTree(Node* n);
  35.  
  36. void DisplayContents(Node* node, std::ostream& outputStream);
  37.  
  38. void DisplaySpaces(int spaceCount, std::ostream& outputStream);
  39.  
  40. public:
  41. AVLTree(void);
  42. ~AVLTree(void);
  43.  
  44. // Should return false if the value already exists in the tree or if memory
  45. // for a new node could not be allocated.
  46. bool Add(int dataValue);
  47.  
  48. int CountLevels();
  49.  
  50. void DisplayContents(std::ostream& outputStream);
  51.  
  52. void DisplayLevels(std::ostream& outputStream);
  53.  
  54. // Gets the maximum value in the tree. Returns 0 if the tree is empty.
  55. int GetMax();
  56.  
  57. bool IsEmpty();
  58. struct Node* insert(struct Node* node, int dataValue);
  59.  
  60. // Returns true if the value was found and removed, false if it was not found
  61. bool Remove(int dataValue);
  62. struct Node* RightRightRotate(struct Node *x);
  63. struct Node* LeftLeftRotate(struct Node *y);
  64. struct Node* RightLeftRotate(struct Node *y);
  65. struct Node* LeftRightRotate(struct Node *y);
  66. struct Node* Balance(struct Node *buffer);
  67. struct Node* find_min(struct Node *buffer);
  68. int which_is_bigger(int x, int y);
  69. int height_difference(struct Node *buffer);
  70. struct Node* delete_node_helper(struct Node *buffer, int data);
  71. //int Balance2(struct Node *buffer);
  72.  
  73. int height(struct node *N);
  74. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement