[prev] 85 [next]

Splay Trees (cont)

Searching in splay trees:

searchSplay(tree,item):
|  Input  tree, item
|  Output address of item if found in tree
|         NULL otherwise
|
|  if tree=NULL then
|     return NULL
|  else
|  |  tree=splay(tree,item)
|  |  if data(tree)=item then
|  |     return tree
|  |  else
|  |     return NULL
|  |  end if
|  end if

where splay() is similar to insertSplay(),
except that it doesn't add a node … simply moves item to root if found, or nearest node if not found