Algorithms for Splay Tree Operations

Insert, Search and Delete are the same as for a standard binary search tree.
The Splay operation is carrid out on the deepest node visited after each operation.
Splay(T,x)
while
p[x] <> NIL
    do y = p[x]
       z = p[y]
       if x = left[root[T]]
          then Right-Rotate(T,root[T])
          else if x = right[root[T]]
                  then Left-Rotate(T,root[T])
                  else if x = left[y] and y = left[z]
                          then Right-Rotate(T,z)
                               Right-Rotate(T,y)
                          else if x = right[y] and y = right[z]
                                  then Left-Rotate(T,z)
                                       Left-Rotate(T,y)
                                  else if x = right[y] and y = left[z]
                                          then Left-Rotate(T,y)
                                               Right-Rotate(T,z)
                                          else if x = left[y] and y = right[z]
                                               then Right-Rotate(T,y)
                                                    Left-Rotate(T,z)