// and now for a tree sort - I know I have spent to long on this but I was stuck writing the report/essay and this has got me interested public void TreeSort() { // start a new tree BinTree sortingTree = new BinTree(numbers[0], "tree sort"); // go thought the array adding number to the tree -this will add the first number twice but the tree will just not do anything but log it failed to add foreach (int number in numbers) { sortingTree.addNode(number, "tree sort"); } // run the indexfrom lowest wich will go thouth the tree and get the indexes from the lowest to the highest - sorted. then go to the start of the link list dblLinked treeSorted = sortingTree.IndexFromLowest(); treeSorted.goToStart(); // the go right will skip the 1st so I will add that one manualy Debug.WriteLine(treeSorted.getData()); numbers[0] = (int)treeSorted.getData(); // start at one as the first has been done already int counter = 1; while (treeSorted.goRight()) { numbers[counter] = (int)treeSorted.getData(); counter++; } }
// this is to check to see if a key exists public bool CheckKey(string key) { // lets get our list dblLinked bucket = storage[getHash(key)]; // first lets see if there is any entry here if (!bucket.IsEmpty()) { // get the start of the list bucket.goToStart(); //check the first if ((string)((object[])bucket.getData())[0] == key) { return(true); } // then loop and check the rest while (bucket.isRight()) { if ((string)((object[])bucket.getData())[0] == key) { return(true); } bucket.goRight(); } } return(false); }
// #################################### iteration buttons ##################### // left side iteration button public void btnLeft_click(object sender, EventArgs e) { // myTree.clearLog(); // lblLog.Text = myTree.fromLowest(); // creating the straight iteration list nodeList = myTree.fromLowest(); if (nodeList == null) { nodeList = new dblLinked(); } // this should fix the app crashing when it gets a null list. and yeah the code is not well formatted but who cares // go to the start of the list nodeList.goToStart(); //display that list item in the label lblLink.Text = nodeList.getData().ToString(); //change the label above the link list display to say straight iteration lblIteration.Text = "Left Side Iteration"; }
public TreeAndList() { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); // lests setup some random nodes Random rnd = new Random(); for (int i = 0; i < 1; i++) { int rnum = rnd.Next(1, 1001); myTree.addNode(rnum, "random node"); Debug.WriteLine("--== " + rnum + "==--"); //nodeList.addToEnd(i + " added node"); // add a node to a test dbl link list } // now lets clear to log to make it easier to see wht I do myTree.clearLog(); // creating the straight iteration list nodeList = myTree.straightItr(); nodeList.goToStart(); lblLink.Text = nodeList.getData().ToString(); Debug.WriteLine("--== " + "dsfgdsghdfsghdfgjdfglhkjdshflghdslkfghjdslfkjghdfslkjg;ldfgj;ldsfhgldsjfhg;lnfghjdfslkjghlsdjfghldsjfg" + "==--"); }