mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
filename and functionname updated
This commit is contained in:
parent
e63c806f25
commit
e77581f788
@ -42,7 +42,7 @@ node *create_node(int data) {
|
|||||||
* param[in,out] root pointer to node pointer to the topmost node of the tree
|
* param[in,out] root pointer to node pointer to the topmost node of the tree
|
||||||
* param[in] data value to be inserted into the tree
|
* param[in] data value to be inserted into the tree
|
||||||
*/
|
*/
|
||||||
void insert_BT(node **root, int data) {
|
void insert_bt(node **root, int data) {
|
||||||
node *new_node = create_node(data);
|
node *new_node = create_node(data);
|
||||||
node *temp; // to be deleted
|
node *temp; // to be deleted
|
||||||
node *prev; // keeps track of the parent of the element deleted
|
node *prev; // keeps track of the parent of the element deleted
|
||||||
@ -94,7 +94,7 @@ void search(node *root, int ele) {
|
|||||||
printf("%s\n", "Element found.");
|
printf("%s\n", "Element found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* performs inorder traversal
|
* performs inorder traversal
|
||||||
* param[in] curr node pointer to the topmost node of the tree
|
* param[in] curr node pointer to the topmost node of the tree
|
||||||
*/
|
*/
|
||||||
@ -106,37 +106,37 @@ void inorder_display(node *curr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* performs postorder traversal
|
* performs postorder traversal
|
||||||
* param[in] curr node pointer to the topmost node of the tree
|
* param[in] curr node pointer to the topmost node of the tree
|
||||||
*/
|
*/
|
||||||
void postorder_BT(node *curr) {
|
void postorder_display(node *curr) {
|
||||||
if (curr != NULL) {
|
if (curr != NULL) {
|
||||||
postorder_BT(curr->llink);
|
postorder_display(curr->llink);
|
||||||
postorder_BT(curr->rlink);
|
postorder_display(curr->rlink);
|
||||||
printf("%d\t", curr->data);
|
printf("%d\t", curr->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* performs preorder traversal
|
* performs preorder traversal
|
||||||
* param[in] curr node pointer to the topmost node of the tree
|
* param[in] curr node pointer to the topmost node of the tree
|
||||||
*/
|
*/
|
||||||
void preorder_BT(node *curr) {
|
void preorder_display(node *curr) {
|
||||||
if (curr != NULL) {
|
if (curr != NULL) {
|
||||||
printf("%d\t", curr->data);
|
printf("%d\t", curr->data);
|
||||||
preorder_BT(curr->llink);
|
preorder_display(curr->llink);
|
||||||
preorder_BT(curr->rlink);
|
preorder_display(curr->rlink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* deletion of a node from the tree
|
* deletion of a node from the tree
|
||||||
* if the node isn't present in the tree, it takes no action.
|
* if the node isn't present in the tree, it takes no action.
|
||||||
* param[in,out] root pointer to node pointer to the topmost node of the tree
|
* param[in,out] root pointer to node pointer to the topmost node of the tree
|
||||||
* param[in] ele value to be deleted from the tree
|
* param[in] ele value to be deleted from the tree
|
||||||
*/
|
*/
|
||||||
void delete_BT(node **root, int ele) {
|
void delete_bt(node **root, int ele) {
|
||||||
node *temp;
|
node *temp;
|
||||||
node *prev;
|
node *prev;
|
||||||
if (*root == NULL)
|
if (*root == NULL)
|
||||||
@ -192,10 +192,10 @@ void delete_BT(node **root, int ele) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* main function
|
* main function
|
||||||
*/
|
*/
|
||||||
void main() {
|
int main() {
|
||||||
printf("BINARY THREADED TREE: \n");
|
printf("BINARY THREADED TREE: \n");
|
||||||
node *root = NULL;
|
node *root = NULL;
|
||||||
int choice, n;
|
int choice, n;
|
||||||
@ -213,24 +213,24 @@ void main() {
|
|||||||
case 1:
|
case 1:
|
||||||
printf("%s\n", "Enter a no:");
|
printf("%s\n", "Enter a no:");
|
||||||
scanf("%d", &n);
|
scanf("%d", &n);
|
||||||
insert_BT(&root, n);
|
insert_bt(&root, n);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
inorder_display(root);
|
inorder_display(root);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
preorder_BT(root);
|
preorder_display(root);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
postorder_BT(root);
|
postorder_display(root);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
printf("%s\n", "Enter a no:");
|
printf("%s\n", "Enter a no:");
|
||||||
scanf("%d", &n);
|
scanf("%d", &n);
|
||||||
delete_BT(&root, n);
|
delete_bt(&root, n);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
printf("%s\n", "Enter a no:");
|
printf("%s\n", "Enter a no:");
|
||||||
@ -239,4 +239,5 @@ void main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (choice != 0);
|
} while (choice != 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user