Facebook
From Ivory Water Vole, 3 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 137
  1. //Inserting a node in AVL tree
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. // A utility function to get maximum of two integers
  6. int max(int a, int b)
  7. {
  8.     return (a > b)? a : b;
  9. }
  10.  
  11. // A tree node
  12. struct Node
  13. {
  14.     int key;
  15.     struct Node *left;
  16.     struct Node *right;
  17. };
  18.  
  19.  
  20. void inOrder(struct Node *root)
  21. {
  22.     if(root != NULL)
  23.     {
  24.         inOrder(root->left);
  25.         printf("%d ", root->key);
  26.         inOrder(root->right);
  27.     }
  28. }
  29.  
  30. // A utility function to get the height of the tree
  31. int height(struct Node *N)
  32. {
  33. }
  34.  
  35.  
  36. /* Helper function that allocates a new node with the given key and
  37.     NULL left and right pointers. */
  38. struct Node* newNode(int key)
  39. {
  40.    
  41. }
  42.    
  43. // Get Balance factor of node N
  44. int getBalance(struct Node *N)
  45. {
  46. }
  47.  
  48.  
  49. // 15, 6, 23, 4, 7
, 5
  50.  
  51. /* Driver program to test above function*/
  52. int main()
  53. {
  54.   struct Node *root = NULL;
  55.  
  56.   /* Constructing tree given in the above figure */
  57.   root = insert(root, 15);
  58.   root = insert(root, 6);
  59.   root = insert(root, 23);
  60.   root = insert(root, 4);
  61.   root = insert(root, 7);
  62.   root = insert(root, 5);
  63.  
  64.   inOrder(root);
  65.  
  66.   return 0;
  67. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Neeldhaara Misra c 3 Years ago.