Formating code

This commit is contained in:
Ashwek Swamy 2019-11-04 16:55:45 +05:30 committed by GitHub
parent 1e255fca0c
commit 3ee9cbdfa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@ int heightDiff(avlNode *node)
return(nodeHeight(node->left) - nodeHeight(node->right));
}
/* Returns the node with min key in the left subtree*/
/* Returns the node with min key in the left subtree*/
avlNode *minNode(avlNode *node)
{
avlNode *temp = node;
@ -59,14 +59,12 @@ avlNode *minNode(avlNode *node)
return temp;
}
void printAVL(avlNode *node, int level)
{
int i;
if(node!=NULL)
{
printAVL(node->right, level+1);
//printf("_");
printf("\n\n");
for(i=0; i<level; i++)
@ -74,7 +72,6 @@ void printAVL(avlNode *node, int level)
printf("%d", node->key);
//printf("_");
printAVL(node->left, level+1);
}
}
@ -121,7 +118,6 @@ avlNode *RightLeftRotate(avlNode *z)
return (leftRotate(z));
}
avlNode *insert(avlNode *node, int key)
{
@ -134,20 +130,15 @@ avlNode *insert(avlNode *node, int key)
node->left = insert(node->left, key); /*Recursive insertion in L subtree*/
else if(key > node->key)
node->right = insert(node->right, key); /*Recursive insertion in R subtree*/
//else
//return node;
/* Node Height as per the AVL formula*/
node->height = (max(nodeHeight(node->left),
nodeHeight(node->right)) + 1);
node->height = (max(nodeHeight(node->left), nodeHeight(node->right)) + 1);
/*Checking for the balance condition*/
int balance = heightDiff(node);
/*Left Left */
if(balance>1 && key < (node->left->key))
return rightRotate(node);
@ -160,17 +151,17 @@ avlNode *insert(avlNode *node, int key)
{
node = LeftRightRotate(node);
}
/*Right Left */
if (balance<-1 && key < (node->right->key))
{
node = RightLeftRotate(node);
}
return node;
return node;
}
avlNode *delete(avlNode *node, int queryNum)
{
if(node == NULL)
@ -210,14 +201,14 @@ avlNode *delete(avlNode *node, int queryNum)
node->right = delete(node->right, temp->key); /*Delete the smallest in the R subtree.*/
}
}
/*single node in tree*/
if(node == NULL)
return node;
/*Update height*/
node->height = (max(nodeHeight(node->left),
nodeHeight(node->right)) + 1);
node->height = (max(nodeHeight(node->left), nodeHeight(node->right)) + 1);
int balance = heightDiff(node);
@ -230,6 +221,7 @@ avlNode *delete(avlNode *node, int queryNum)
{
node = LeftRightRotate(node);
}
/*Right Right */
if((balance<-1) && (heightDiff(node->right) >= 0))
return leftRotate(node);
@ -257,14 +249,11 @@ avlNode *findNode(avlNode *node, int queryNum)
return node;
}
void printPreOrder(avlNode *node)
{
if(node == NULL)
return;
// printf("\nprintPreOrder function\n");
//printf(" %d-H:%d \t", (node->key), (node->height));
printf(" %d ", (node->key));
printPreOrder(node->left);
printPreOrder(node->right);
@ -274,9 +263,7 @@ void printInOrder(avlNode *node)
{
if(node == NULL)
return;
// printf("\nprintPreOrder function\n");
printInOrder(node->left);
//printf(" %d-H:%d \t", (node->key), (node->height));
printf(" %d ", (node->key));
printInOrder(node->right);
}
@ -285,16 +272,11 @@ void printPostOrder(avlNode *node)
{
if(node == NULL)
return;
// printf("\nprintPreOrder function\n");
printPostOrder(node->left);
printPostOrder(node->right);
//printf("%d ", (node->key));
//printf(" %d-H:%d \t", (node->key), (node->height));
printf(" %d ", (node->key));
}
int main()
{
int choice;
@ -327,8 +309,6 @@ int main()
flag=0;
printf("\n\t\tExiting, Thank You !!\n");
break;
return 0;
}
case 1:
@ -398,6 +378,7 @@ int main()
printAVL(root, 1);
printf("\n");
}
break;
}
@ -438,8 +419,6 @@ int main()
flag=0;
printf("\n\t\tExiting, Thank You !!\n");
break;
return 0;
}
}