private List <ISBNclass> GetAllIsbns(BSTnode current, List <ISBNclass> currentList) { if (current == null) { return(currentList); } ISBNclass alISBN = new ISBNclass(); alISBN.ISBN = current.bstKey; currentList.Add(alISBN); GetAllIsbns(current.LeftNode, currentList); GetAllIsbns(current.RightNode, currentList); return(currentList); }
public List <ISBNclass> GetISBN() { ISBNclass currentISBN = new ISBNclass(); List <ISBNclass> isbnList = new List <ISBNclass>(); BSTnode currentBSTnode; // walk the tree by using this pointer to the current node Stack myStack = new Stack(); // instantiate the .NET supplied stack class, which will hold objects if (bstTop == null) // if the stack is empty ... { return(null); // nothing to print } else// adjust our pointer to the top node in the BST { currentBSTnode = bstTop; } bool done = false; // get out of our while loop when this is set to true while (!done) // loop until we are done { if (currentBSTnode != null) { isbnList.Add(new ISBNclass(currentBSTnode.bstKey)); } if (currentBSTnode == null) // if there is no node here { if (myStack.Count == 0) // and the stack is empty, we have walked the entire tree, so done { done = true; } else// otherwise go back up the tree one level, by doing a pop { currentBSTnode = (BSTnode)myStack.Pop(); // (need to cast object back to a BSTnode) currentBSTnode = currentBSTnode.RightNode; // now go down the right side } } else // if we have not moved down to a null { myStack.Push(currentBSTnode); // save this upper node onto the top of the stack currentBSTnode = currentBSTnode.LeftNode; // and take a step down the left side } } return(isbnList); }