Assignment 4 Adsl
Assignment 4 Adsl
Assignment 4 Adsl
- 22230143 A
ASSIGNMENT 4 ADSL
a) Create an in-order single threaded binary search tree and perform the
traversals.
CODE:
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
bool isThreaded;
Node(int val) {
data = val;
left = right = nullptr;
isThreaded = false;
}
};
current = current->right;
}
}
int main() {
Node* root = nullptr;
insert(root, 50);
insert(root, 30);
insert(root, 20);
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
return 0;
}
OUTPUT:
b) Create an in-order Double threaded binary search tree and perform the
traversals.
CODE:
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
Node* leftThread;
Node* rightThread;
};
newNode->right = nullptr;
newNode->leftThread = nullptr;
newNode->rightThread = nullptr;
return newNode;
}
current = current->rightThread;
else
current = leftMost(current->right);
}
}
int main() {
Node* root = nullptr;
root = insert(root, 5);
insert(root, 3);
insert(root, 7);
insert(root, 2);
insert(root, 4);
insert(root, 6);
insert(root, 8);
return 0;
}
OUTPUT:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
c) Create a threaded binary search tree with insert, search and delete leaf node
operations.
CODE:
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
bool leftThread;
bool rightThread;
};
return root;
}
else
current = nullptr;
}
}
if (parent != nullptr) {
if (parent->left == nodeToDelete) {
parent->left = nodeToDelete->left;
parent->leftThread = true;
if (nodeToDelete->rightThread)
parent->left->right = parent;
} else {
parent->right = nodeToDelete->right;
parent->rightThread = true;
if (nodeToDelete->leftThread)
parent->right->left = parent;
}
} else {
root = nullptr;
}
delete nodeToDelete;
return root;
}
current = leftMost(current->right);
}
}
int main() {
Node* root = nullptr;
root = insert(root, 5);
insert(root, 3);
insert(root, 7);
insert(root, 2);
insert(root, 4);
insert(root, 6);
insert(root, 8);
return 0;
}
OUTPUT:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
FAQs
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A