Programming Assissment5
Programming Assissment5
struct Node {
int data;
newNode->data = data;
return newNode;
if (root == NULL) {
return createNode(data);
} else {
return root;
return root;
}
return search(root->left, key);
if (result != NULL) {
} else {
int main() {
searchResult(result1, key1);
struct Node* result2 = search(root, key2);
searchResult(result2, key2);
return 0;
C) #include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = data;
return newNode;
if (root == NULL) {
return createNode(data);
} else {
return root;
if (root == NULL) {
return 0;
(*comparisons)++;
if (root->data == key) {
return 1;
} else {
int comparisons = 0;
if (found) {
} else {
}
}
int main() {
searchResult(root, key1);
searchResult(root, key2);
return 0;
}
2)
ANS:
Preorder Traversal: 1 2 4 8 9 5 10 11 3 6 13 7 14
Inorder Traversal: 8 4 9 2 10 5 11 1 13 6 3 14 7
Postorder Traversal: 8 9 4 10 11 5 2 13 6 14 7 3 1
B)
36
/ \
22 44
/ \
10 42
/ \
3 16
\
25
\
23
\
24
C)
36
/ \
25 44
/ \
10 42
/ \
3 16
\
24
D)
Inorder: 3 10 16 24 25 36 44
Postorder: 3 16 24 10 25 44 36
Preorder: 36 25 10 3 16 24 44