public static SNode reverseList(SNode n) {
   SNode last = n;
   SNode dummy = new SNode(0);
   while (n != null) {
     SNode newNode = new SNode(n.key);
     newNode.next = dummy.next;
     dummy.next = newNode;
     n = n.next;
   }
   return dummy.next;
 }
 /**
  * Creates or resets fields of a node. Called only from transfer where the node to push on stack
  * is lazily created and reused when possible to help reduce intervals between reads and CASes
  * of head and to avoid surges of garbage when CASes to push nodes fail due to contention.
  */
 static SNode snode(SNode s, Object e, SNode next, int mode) {
   if (s == null) s = new SNode(e);
   s.mode = mode;
   s.next = next;
   return s;
 }