1. Algorithm search (x)
2. {
3. found:= false;
4. t:= tree;
5. while ( ( t != 0) and not found) do
6. {
7. if (x =(t-> data)) then found:= true;
8. else if(x < ( t-> data)) then t::= ( t-> l. child);
9. else t::= ( t-> r. child);
10. }
11. if ( not found) then return 0;
12. else return t;
13. }
Binary search tree output:
Tree - Insert and Delete and search operations :
1.insert 2.delete 3.search 4.exit
enter choice:1
Key to insert ? 5
Tree display :
5
1.insert 2.delete 3.search 4.exit
enter choice:1
Key to insert ? 6
Tree display :
6
5
1.insert 2.delete 3.search 4.exit
enter choice:1
Key to insert ? 4
Tree display :
6
5
4
1.insert 2.delete 3.search 4.exit
enter choice:1
Key to insert ? 8
Tree display :
8
6
5
4
1.insert 2.delete 3.search 4.exit
enter choice: 2
Key to delete ?5
tree Display :
8
6
4
1.insert 2.delete 3.search 4.exit
enter choice:2
Key to delete ?6
tree Display :
8
4
1.insert 2.delete 3.search 4.exit
enter choice:2
Key to delete ?4
tree Display :
8
1.insert 2.delete 3.search 4.exit
enter choice:2
Key to delete ?8
tree Display :
1.insert 2.delete 3.search 4.exit
enter choice:4
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment