week13 format mowgli AVL

This commit is contained in:
2021-05-26 20:20:01 +08:00
parent 679b38ab78
commit cacf5445ad
4 changed files with 424 additions and 512 deletions

View File

@@ -1,59 +1,58 @@
typedef struct Node Node;
typedef struct Node
{
int key, height;
Node *left, *right;
typedef struct Node {
int key, height;
Node *left, *right;
} Node;
Node *insertNode(Node **proot, int x);
/*
function:
inserts a new node to the tree
inserts a new node to the tree
input:
proot - pointer to the pointer to the tree root
x - the key of the new node
proot - pointer to the pointer to the tree root
x - the key of the new node
output:
returns a pointer to the newly inserted node
returns NULL if insertion is not successful
returns a pointer to the newly inserted node
returns NULL if insertion is not successful
*/
Node *deleteNode(Node **proot, int x);
/*
function:
removes a node from the tree without freeing it
removes a node from the tree without freeing it
input:
proot - pointer to the pointer to the tree root
x - the key of of the node to be deleted
proot - pointer to the pointer to the tree root
x - the key of of the node to be deleted
output:
returns a pointer to the deleted node
returns NULL if no such node exists
returns a pointer to the deleted node
returns NULL if no such node exists
*/
Node *findNode(Node *root, int x);
/*
function:
searches for a node in the tree
searches for a node in the tree
input:
root - pointer to the tree root
x - the key of of the node to be searched
root - pointer to the tree root
x - the key of of the node to be searched
output:
returns a pointer to the found node
returns NULL if no such node exists
returns a pointer to the found node
returns NULL if no such node exists
*/
void destroyTree(Node *root);
/*
function:
deletes all the nodes in the tree and frees the memory occupied by them
deletes all the nodes in the tree and frees the memory occupied by them
input:
root - pointer to the tree node
root - pointer to the tree node
*/
void printTree(Node *root);
/*
function:
prints ascii tree for given Node structure
this function is already implemented in printTree.cpp
prints ascii tree for given Node structure
this function is already implemented in printTree.cpp
input:
root - pointer to the tree node
root - pointer to the tree node
*/