Search code examples
c#avl-treeinorder

InOrder sorting of a class within a AVLTtree by name to a text box


I appear to have the tree displayed in order, however i want to display the country name in the text box instead of what it is currently giving me Here is the code I have currently have relating to this issue. An FYI the tree populates from a file read in.

I want in the text box Argentina, Australia, Brazil, etc. but current have "FormWork.Country, FormWork.Country, etc". Looking at them in the Autos shows they are the correct order, just not returning the Name only.

This is within Form1.cs

public partial class Form1 : Form
{
AVLTree<Country> countryTree = new AVLTree<Country>();
string buffer = null;

public form1()
{
LoadFile();
InitializeComponent();
orderTree();
}

public void orderTree()
{
countryTree.InOrder(ref buffer);
txtOrder.Text = buffer;
}
}

This is where .InOrder is

My issues seems to be that I can't specifically retrieve "tree.Data.countryName" from the Country.cs class


Solution

  • instead of calling

    buffer += tree.Data.toString() + ",";
    

    in the buffer append line of your in-order traversal, call something along the lines of

    buffer += tree.Data.CountryName + ", ";
    

    to access the string of the property you are trying to print rather than a representation of the Country object which will be "FormWork.Country".

    Second off, you should put all of your code in the question rather than linking to 2 different places.