I am working with a link list. My constructor takes arrays with items in it or appends an item(one at time) to the list through BtnAddTree
click. For experiment
Develop a way to compare the object properly. is tree type unique? maybe you need a full icomparable?
then create a method in the listoftrees class
public int getPosition(fruit_trees tree)
{
fruit_trees ft = first_tree;
if(ft.tree_type == tree.tree_type)
{
return 0; //or return 1 depending on how you want to index stuff
}
int i = 1;//possibly set to 2 if returning 1 above
while(ft.next_tree != null)
{
ft = ft.next_tree;
if(ft.tree_type == tree.tree_type)
{
return i;
}
i++;
}
return -1; //or something else here to show that its not in the list
}
also as a side note ..Dont set the label value in the class in the method Current_Tree(). That should return a fruit_trees object and the btn click methods should set the label value .
you should actually just get rid of that method completely(unless there is some reason for it outside of the code above.