/** Node class for skip lists. * Since this is just a skeleton implementation, I'm leaving out the item * of real object data. As a result, the only "data" we're storing is the key * at each node. * I'm making the pointer attributes protected, so that in SkipList.java * you may easily access them. */ public class Node { protected Node up; protected Node down; protected Node left; protected Node right; private int key; protected int level; // For debugging, convenient to know what row I'm on. public Node(int k, int l) { up = null; down = null; left = null; right = null; key = k; level = l; } public int getKey() { return key; } /** * Returns a user-friendly version of the key. * @return key or +inf or -inf */ public String getOutputKey() { String prettyKey = Integer.toString(key); if (key == Integer.MAX_VALUE) { prettyKey = "+inf"; } else if (key == Integer.MIN_VALUE) { prettyKey = "-inf"; } return prettyKey; } // A handy method to help when debugging. public String toString() { StringBuilder build = new StringBuilder(); build.append("" + this.getOutputKey() + "("); if (this.up != null) build.append("up " + this.up.getOutputKey() + " "); if (this.down != null) build.append("down " + this.down.getOutputKey() + " "); if (this.left != null) build.append("left " + this.left.getOutputKey() + " "); if (this.right != null) build.append("right " + this.right.getOutputKey() + " "); build.append("level " + level + ")"); return build.toString(); } }