ClavinJune

avl

Nov 7th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. int len (char text[]) {
  5. int i = 0;
  6. while (text[++i]);
  7. return i;
  8. }
  9.  
  10. int max (int a, int b) {
  11. return a > b ? a : b;
  12. }
  13.  
  14. struct Node {
  15. char key[101];
  16. int height;
  17. struct Node *left, *right;
  18. };
  19.  
  20. int height (struct Node *node) {
  21. return !node ? 0 : node->height;
  22. }
  23.  
  24. int bFactor (struct Node *node) {
  25. return !node ? 0 : height(node->left) - height(node->right);
  26. }
  27.  
  28. struct Node *rightRotate (struct Node *node) {
  29. struct Node *x = node->left;
  30. struct Node *y = x->right;
  31.  
  32. x->right = node;
  33. node->left = y;
  34.  
  35. node->height = max(height(node->left), height(node->right)) + 1;
  36. x->height = max(height(x->left), height(x->right)) + 1;
  37.  
  38. return x;
  39. }
  40.  
  41. struct Node *leftRotate (struct Node *node) {
  42. struct Node *x = node->right;
  43. struct Node *y = x->left;
  44.  
  45. x->left = node;
  46. node->right = y;
  47.  
  48. node->height = max(height(node->left), height(node->right)) + 1;
  49. x->height = max(height(x->left), height(x->right)) + 1;
  50.  
  51. return x;
  52. }
  53.  
  54. struct Node *insert
  55.  
  56. int main (int argc, char **argv) {
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment