Facebook
From Neeldhaara Misra, 4 Years ago, written in C.
This paste is a reply to Untitled from Ivory Water Vole - go back
Embed
Viewing differences between Untitled and Re: Untitled
//Inserting a node in AVL tree 
#include 
#include 

// A utility function to get maximum of two integers 
int max(int a, int b) 

    return (a > b)? a : b; 


// A tree node 
struct Node 

    int key; 
    struct Node *left; 
    struct Node *right; 
}; 


void inOrder(struct Node *root) 

    if(root != NULL) 
    { 
        inOrder(root->left); 
        printf("%d ", root->key); 
        inOrder(root->right); 
    } 

  
// A utility function to get the height of the tree 
int height(struct Node *N) 


  
  
/* Helper function that allocates a new node with the given key and 
    NULL left and right pointers. */
struct Node* newNode(int key) 

    

    
// Get Balance factor of node N 
int getBalance(struct Node *N) 


  

// 15, 6, 23, 4, 7
, 5
  
/* Driver program to test above function*/
int main() 

  struct Node *root = NULL; 
  
  /* Constructing tree given in the above figure */
  root = insert(root, 15); 
  root = insert(root, 6); 
  root = insert(root, 23); 
  root = insert(root, 4); 
  root = insert(root, 7); 
  root = insert(root, 5); 
  
  inOrder(root); 
  
  return 0; 
captcha