Question: Create a binary search tree (you may choose to use the Graphics class in C# OR just display an inorder traversal of nodes as a

Create a binary search tree (you may choose to use the Graphics class in C# OR just display an inorder traversal of nodes as a console output) from a given array of numbers. For Example, if the given array is 11, 6, 4, 5, 8, 10, 19, 17, 43, 31, 49. You are supposed to program an inorder traversal displaying 4,5,6,8,10,11,17,19,31,43,49.

Design a program that: accepts any a sequence of numbers in an array (10 points) draws a binary search tree using the insertion method (30 points) o NOTE: insertion method uses a tree search method for locating the position of the new node. allows user to insert any new number as a new node in the BST (10 points) allows user to delete any existing node whose child nodes are internal nodes (30 points) after each insertion or deletion from the user, displays the inorder traversal of the tree (20 points)

Current Code (I know it is jumbled and all over the place, trying to get functional and then will clean it up.)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Binary_Search_Assignment { //Node Creation public class Node { public int data; public Node left, right; private object value;

public Node(int data) { this.data = data; left = right = null; }

public override string ToString() { return value.ToString(); }

}

//treeNode Creation public class TreeNode { object data; TreeNode left; TreeNode right; }

class BinaryTree { private BNode root;//root of the tree public BNode GetRoot() { return root; } public BinaryTree() // default constructor { root = null; } public BinaryTree(BNode rootNode) // constructor { root = rootNode; } }

public class BNode { private T data; public BNode left, right;//left child and right child public BNode(T item) { data = item; left = null; right = null; } public BNode(T item, BNode leftNode, BNode rightNode) { data = item; left = leftNode; right = rightNode; } }

//Creating index value class Index { public int index = 0; }

class Program { //inputs public string inputNum; public string deleteNum; public double addNum; public double byeNum;

//This is where we will call each method within our program for testing static void Main(string[] args) { /*Console.WriteLine("What number would you like to insert?"); inputNum = Console.ReadLine; try { addNum = double.Parse(inputNum); } catch { Console.WriteLine("Error, No number entered!"); } insert();

Console.WriteLine("What number would you like to insert?"); deleteNum = Console.ReadLine; try { byeNum = double.Parse(deleteNum); } catch { Console.WriteLine("Error, No number entered!"); } delete();*/ //inOrderSort(); var tree = new BinaryTree(); int[] given = new int[] { 1, 7, 5, 50, 40, 10 }; int size = given.Length;

Node root = tree.constructTree(given, size);

Console.WriteLine("Inorder traversal of" + "the constructed tree:"); tree.printInorder(root);

//Console.WriteLine("sorted === " + bst); //search(); }

//method for insertion private static void insert() { }

//method for deletion private static void delete() { }

//method for sorting - Sheldon private static void inOrderSort() { if (v.left != null) { inOrderSort(leftNode, v); } return v.element; if (v.right != null) { inOrderSort(rightNode, v); } }

//method for searching private BNode treeSearch(BNode v, T tTarget) { if (v == null) //there is no such a node in the tree return null; else if (compare(tTarget, v.getValue()) == 0)//find it { return v; } else if (compare(tTarget, v.getValue()) < 0)//go to left { return treeSearch(v.left, tTarget); } else { return treeSearch(v.right, tTarget);//go to right }

}

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!