next up previous
Next: Implementing Pointers as Arrays Up: CSE 2320: Algorithms and Previous: Unsorted Double List with

Sorted Double List with Sentinel

   Min(L)
      return nil(L)

   Max(L)
      return prev(nil(L))

   Predecessor(L,x)
      return prev(x)

   Successor(L,x)
      return next(x)

   Insert(L,x)
      y = nil(L)
      while next(y) <> nil(L)  and  key(next(y)) < key(x)
         y = next(y)
      next(x) = next(y)
      prev(next(x)) = x
      next(y) = x
      prev(x) = y

Delete and Search: same as unsorted double lists

Note: use of sentinels may in some situations (e.g., many short lists), so use with caution.



Copyright © 1998 The University of Texas at Arlington