// 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); }
public void btnSaveRight_click(object sender, EventArgs e) { if (saveList.isRight()) { saveList.goRight(); lblSaveList.Text = saveList.ToString(); } else { DisplayAlert("", "end of list", "OK"); } }
public void btnLinkRight_click(object sender, EventArgs e) { // DisplayAlert("node found", nodeList.isRight().ToString(), "Okay"); if (nodeList.isRight()) { nodeList.goRight(); lblLink.Text = nodeList.getData().ToString(); } else { DisplayAlert("", "end of list", "OK"); } }
// ###################################### Straight Iteration // this is a left first straight iteration otherwise known as a level order traversal public dblLinked straightItr() { // check that the trunk exists before doing anything if (trunk != null) { dblLinked straightList = new dblLinked(trunk); // if I dont add a least one more node to the list // the loop will end at the start /* * if(trunk.left!= null) * { * straightList.addToEnd(trunk.left); * } * if (trunk.right != null) * { * straightList.addToEnd(trunk.right); * } * /* it looks like a do while works instead of a while loop*/ do { // ok so to make the line of code readablely short lets pull the current // node from the list with a name TreeNode tempTreeNode = (TreeNode)straightList.getData(); // if it has a left node add it to list if (tempTreeNode.left != null) { straightList.addToEnd(tempTreeNode.left); } // ditto for right if (tempTreeNode.right != null) { straightList.addToEnd(tempTreeNode.right); } // go to the next node in the list //straightList.goRight(); } while (straightList.goRight()); // well thats it for the loop // it should should get though them all as it will stopp adding more // at the leaf nodes return(straightList); } else { return(null); } }