//given array in main class
class Program
{
static void Main(string[] args)
{
int[] nums = new int[] { 1, 5, 7, 10, 20, 12};
BinaryTree bt = new BinaryTree();
//what I want to do
bt.insertElement(45);
}
}
// don't mind that the class says binarytree I just want to know how to insert a number in an array
public class BinaryTree
{
public void insertElement(int num)
{
//not sure how to go about it
}
}
-
You cant insert element to an array. Why dont you use just List<T>? If you have to or want to use array, you should create a list from existing array then add new element to List then convert it back to array. But why do you even need this?SeLeCtRa– SeLeCtRa2021-03-05 23:01:04 +00:00Commented Mar 5, 2021 at 23:01
-
it's part of my assignment where my teacher wants it where a user can insert a new value into an array then use the numbers of that array to insert that into a binary tree then print out the values using in-order traversalJean Coupet– Jean Coupet2021-03-05 23:29:01 +00:00Commented Mar 5, 2021 at 23:29
Add a comment
|