PROCEDURE AddNodeToBinaryTree(NewName, NewScore)

	IF Root = 0
		THEN
			Root ← NextFreePosition
		ELSE
			//traverse the tree to find the position for the new value
			CurrentPosition ← Root
			LastMove ← ‘X’
			REPEAT
				PreviousPosition ← CurrentPosition
				IF NewScore < ThisTree[CurrentPosition].Score
					THEN
						//move left
						LastMove ← ‘L’
						CurrentPosition ← ThisTree[CurrentPosition].LeftP
					ELSE
						// move right
						LastMove ← ‘R’
						CurrentPosition ← ThisTree[CurrentPosition].RightP
				ENDIF
			UNTIL CurrentPosition = 0
	ENDIF

	IF LastMove = ‘R’
		THEN
			ThisTree[PreviousPosition].RightP ← NextFreePosition
		ELSE
			ThisTree[PreviousPosition].LeftP ← NextFreePosition
	ENDIF
	NextFreePosition ← ThisTree[NextFreePosition].LeftP 
ENDPROCEDURE