// left side iteration or list from lowest to highest recording any time we dont go up the tree otherwise known as pre order traversal public dblLinked preOrderItr(TreeNode checkIt, bool fromChild, dblLinked results) { if (fromChild) { /* * if (checkIt.right == null) * { * results.addToEnd(checkIt.ToString()); * }*/ // parent null means we are back at the trunk if (checkIt.parent != null) { // if its coming from the left go parent right(sister) if possible otherwise go up if (checkIt.parent.right != null && checkIt.sortingNum < checkIt.parent.sortingNum) { // results.addToEnd(checkIt.parent.ToString()); return(preOrderItr(checkIt.parent.right, false, results)); } else { return(preOrderItr(checkIt.parent, true, results)); } } else { // back to trunk so now its over return(results); } } // ok so that is if its coming from a kid now if it coming from anywhere else else { // just record as long as we are not going back up results.addToEnd(checkIt.ToString()); // first try to go down left(son) if not try right(daughter) if (checkIt.left != null) { return(preOrderItr(checkIt.left, false, results)); } else { // results.addToEnd(checkIt.ToString()); //well there was no son(left) so lets see if there was a daughter(right) if (checkIt.right != null) { return(preOrderItr(checkIt.right, false, results)); } else { // no left(son) or right(daughter) so if there is no parent right(sister) to to the parent if (checkIt.parent != null) { // I forgot to check for a sister if (checkIt.parent.right != null && checkIt.sortingNum < checkIt.parent.sortingNum) { // results.addToEnd(checkIt.parent.ToString()); return(preOrderItr(checkIt.parent.right, false, results)); } else { return(preOrderItr(checkIt.parent, true, results)); } } else { // no son, daughter, or parent so we are alone at the trunk and can end return(results); } } } } //return results; }
///////////////////////////////// iterations // left side iteration or list from lowest to highest otherwise known as in order traversal public dblLinked leftSideItr(TreeNode checkIt, bool fromChild, dblLinked results) { if (fromChild) { if (checkIt.right == null) { results.addToEnd(checkIt.ToString()); } if (checkIt.parent != null) { if (checkIt.parent.right != null && checkIt.sortingNum < checkIt.parent.sortingNum) { results.addToEnd(checkIt.parent.ToString()); return(leftSideItr(checkIt.parent.right, false, results)); } else { return(leftSideItr(checkIt.parent, true, results)); } } else { return(results); } } // ok so that is if its coming from a kid now if it coming from anywhere else else { if (checkIt.left != null) { return(leftSideItr(checkIt.left, false, results)); } else { results.addToEnd(checkIt.ToString()); if (checkIt.right != null) { return(leftSideItr(checkIt.right, false, results)); } else { if (checkIt.parent != null) { // I forgot to check for a sister if (checkIt.parent.right != null && checkIt.sortingNum < checkIt.parent.sortingNum) { results.addToEnd(checkIt.parent.ToString()); return(leftSideItr(checkIt.parent.right, false, results)); } else { return(leftSideItr(checkIt.parent, true, results)); } } else { return(results); } } } } //return results; }