logo

Implementation of Binary Search Tree in Java

   

Added on  2023-01-17

13 Pages706 Words64 Views
Running Head: IMPLEMENTATION OF BINARY SEARCH TREE IN JAVA
IMPLEMENTATION OF BINARY SEARCH TREE IN JAVA
Name of the Student:
Name of the University:
Author Note:

IMPLEMENTATION OF BINARY SEARCH TREE IN JAVA1
Table of Contents
The java code of BST.java...............................................................................................................2
Outputs of the program..................................................................................................................10

IMPLEMENTATION OF BINARY SEARCH TREE IN JAVA2
The java code of BST.java
public class BST implements Tree
{
//================
// variables
//================
// Tree Root
private BSTNode root;
//================
// Constructors
//================
// Create an empty Binary search Tree with a Root set to null
public BST()
{
root = null;
}
//================
// Methods

IMPLEMENTATION OF BINARY SEARCH TREE IN JAVA3
//================
// Print the Binary search Tree
public void display()
{
System.out.print("( ");
traverse(root);
System.out.println(" )");
}
// A recursive function that traverses and prints out
// the binary search tree with an inorder traversal.
private void traverse(BSTNode node)
{
if (node == null)
return;
traverse(node.left);
System.out.print(node.val +" ");
traverse(node.right);

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
CS4343 Programming Assignment
|19
|2084
|97