/// <summary> /// Method for finding the leaf in the BTree where a specified value is stored /// </summary> /// <param name="value">The specified value to search for</param> /// <returns>The Leaf that contains the specified value</returns> public Leaf FindLeaf(int value) { //Initialize starting point Index SearchIndex = new Index(Root); GetNodesTraveled.Add(SearchIndex.ToString()); MainStack.Clear(); //Find Deepest Index bool foundLeaf = false; while (foundLeaf == false) { //Mark Index in MainStack MainStack.Push(SearchIndex); if (SearchIndex.IndexList.Count == 0) { //Exit once found foundLeaf = true; } else { //Find the next Index to go to SearchIndex = FindIndex(SearchIndex, value); GetNodesTraveled.Add(SearchIndex.ToString()); } } //Find Leaf needed to insert into for (int i = 1; i < SearchIndex.Items.Count; i++) { GetNodesTraveled.Add(SearchIndex.LeafList[i].ToString()); if (value < SearchIndex.Items[i]) { return(SearchIndex.LeafList[i - 1]); } } //Return last leaf in index return(SearchIndex.LeafList[SearchIndex.LeafList.Count - 1]); }