All pastes #733916 Raw Edit

Untitled

public java v1 · immutable
·published 2007-10-12 05:30 UTC
rendered paste body
public void insertThreaded(E x) {	if(x.compareTo(root.getData())==0)return; //base case, otherwise we could do things that we dont want to do.	ThreadedTreeNode<E> current = root; //Do you use the name root? generally you dont use root for transversing. We start it off at root and transverse from there.		while(((x.compareTo(current.getData())<0) ? current.getLeftChild() != null : current.getRightChild() != null ))	{		if(x.compareTo(current.getData()) == 0)			return; //trees do not have duplicates!		current = ((x.compareTo(current.getData()) < 0) ? current.getLeftChild() : current.getRightChild());	}		//and create the new node and call it day. 	if(x.compareTo(current.getData()) <0)		current.setLeftNode( new ThreadedTreeNode<E> (x) );	else		current.setRightNode(new ThreadedTreeNode<E> (x) );}