S.add(x)
  pred := S.head
  pred.lock()
  curr := pred.next
  curr.lock()
  while (curr.key < x)
    pred.unlock()
    pred := curr
    curr := pred.next
    curr.lock()
  if curr.key = x then
    pred.unlock()
    curr.unlock()
    return false
  else
    node := new Node(x)
    node.next := curr
    pred.next := node
    pred.unlock()
    curr.unlock()
    return true

S.remove(x)
  pred := S.head
  pred.lock()
  curr := pred.next
  curr.lock()
  while (curr.key < x)
    pred.unlock()
    pred := curr
    curr := pred.next
    curr.lock()
  if curr.key = x then
    pred.next := curr.next
    pred.unlock()
    curr.unlock()
    return true
  else
    pred.unlock()
    curr.unlock()
    return false

S.contains(x)
  curr := S.head
  curr.lock()
  while (curr.key < x)
    temp := curr
    curr := curr.next
    curr.lock()
    temp.unlock()
  return (curr.key = x)