Project Of DataStructure Tree node All Code
Project Of DataStructure Tree node All Code
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
struct Node {
int data;
};
if (newNode == NULL) {
exit(1);
newNode->data = data;
return newNode;
return newNode;
while (current) {
parent = current;
current = current->left;
else
current = current->right;
parent->left = newNode;
else
parent->right = newNode;
return root;
// Iterative search in BST. Returns pointer to the node if found; otherwise NULL.
while (root) {
if (root->data == key)
return root;
root = root->left;
else
root = root->right;
}
return NULL;
while (root->left)
root = root->left;
return root->data;
while (root->right)
root = root->right;
return root->data;
queue[rear++] = root;
if (current->left)
queue[rear++] = current->left;
if (current->right)
queue[rear++] = current->right;
printf("\n");
while (current) {
stack[++top] = current;
current = current->left;
current = stack[top--];
current = current->right;
printf("\n");
if (root == NULL)
return;
struct Node* stack[100];
stack[++top] = root;
if (current->right)
stack[++top] = current->right;
if (current->left)
stack[++top] = current->left;
printf("\n");
if (root == NULL)
return;
stack1[++top1] = root;
if (current->left)
stack1[++top1] = current->left;
if (current->right)
stack1[++top1] = current->right;
printf("\n");
// This function deletes the node with key "key" and returns the new root.
parent = current;
current = current->left;
else
current = current->right;
if (current == NULL) {
root = NULL;
parent->left = NULL;
else
parent->right = NULL;
free(current);
while (successor->left) {
successorParent = successor;
successor = successor->left;
current->data = successor->data;
if (successorParent->left == successor)
successorParent->left = successor->right;
else
successorParent->right = successor->right;
free(successor);
if (parent == NULL)
root = child;
parent->left = child;
else
parent->right = child;
free(current);
return root;
if (root == NULL) {
printf("Tree is empty.\n");
return;
int levels[100];
queue[rear] = root;
levels[rear] = 0;
rear++;
int currentLevel = 0;
printf("Level %d: ", currentLevel);
front++;
currentLevel = lev;
if (curr->left) {
queue[rear] = curr->left;
levels[rear] = lev + 1;
rear++;
if (curr->right) {
queue[rear] = curr->right;
levels[rear] = lev + 1;
rear++;
printf("\n");
int main() {
// 1. Display Tree
// 2. Search
// 4. Delete a Node
// 5. Find Minimum
// 6. Find Maximum
// 7. Pre-order Traversal
// 8. In-order Traversal
// 9. Post-order Traversal
// 11. Exit
do {
printf("\n======================================\n");
printf("3. Insert new node(s) (line by line; non-numeric input stops insertion)\n");
printf("11. Exit\n");
if(scanf("%d", &choice) != 1) {
break;
}
switch (choice) {
case 1:
displayFullTree(root);
break;
case 2:
scanf("%d", &value);
if (searchNode(root, value))
else
break;
case 3: {
while(getchar() != '\n');
char input[20];
while (1) {
break;
input[strcspn(input, "\n")] = 0;
break;
break;
}
case 4:
scanf("%d", &value);
break;
case 5:
if (root)
else
printf("Tree is empty.\n");
break;
case 6:
if (root)
else
printf("Tree is empty.\n");
break;
case 7:
preOrderTraversal(root);
break;
case 8:
inOrderTraversal(root);
break;
case 9:
postOrderTraversal(root);
break;
case 10:
printf("Level-order traversal: ");
levelOrderTraversal(root);
break;
case 11:
break;
default:
return 0;
}
*/ Running Project