From e484fe890ebb7b01f01a8ce54bfa8464fad00816 Mon Sep 17 00:00:00 2001 From: Liam Huang Date: Tue, 30 Oct 2018 14:29:17 +0800 Subject: [PATCH] [java][17_skiplist] typo fix [forwords -> forwards] --- java/17_skiplist/SkipList.java | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/java/17_skiplist/SkipList.java b/java/17_skiplist/SkipList.java index f6bcd70..8e62c20 100644 --- a/java/17_skiplist/SkipList.java +++ b/java/17_skiplist/SkipList.java @@ -21,13 +21,13 @@ public class SkipList { public Node find(int value) { Node p = head; for (int i = levelCount - 1; i >= 0; --i) { - while (p.forwords[i] != null && p.forwords[i].data < value) { - p = p.forwords[i]; + while (p.forwards[i] != null && p.forwards[i].data < value) { + p = p.forwards[i]; } } - if (p.forwords[0] != null && p.forwords[0].data == value) { - return p.forwords[0]; + if (p.forwards[0] != null && p.forwards[0].data == value) { + return p.forwards[0]; } else { return null; } @@ -45,15 +45,15 @@ public class SkipList { Node p = head; for (int i = level - 1; i >= 0; --i) { - while (p.forwords[i] != null && p.forwords[i].data < value) { - p = p.forwords[i]; + while (p.forwards[i] != null && p.forwards[i].data < value) { + p = p.forwards[i]; } update[i] = p; } for (int i = 0; i < level; ++i) { - newNode.forwords[i] = update[i].forwords[i]; - update[i].forwords[i] = newNode; + newNode.forwards[i] = update[i].forwards[i]; + update[i].forwards[i] = newNode; } if (levelCount < level) levelCount = level; @@ -63,16 +63,16 @@ public class SkipList { Node[] update = new Node[levelCount]; Node p = head; for (int i = levelCount - 1; i >= 0; --i) { - while (p.forwords[i] != null && p.forwords[i].data < value) { - p = p.forwords[i]; + while (p.forwards[i] != null && p.forwards[i].data < value) { + p = p.forwards[i]; } update[i] = p; } - if (p.forwords[0] != null && p.forwords[0].data == value) { + if (p.forwards[0] != null && p.forwards[0].data == value) { for (int i = levelCount - 1; i >= 0; --i) { - if (update[i].forwords[i] != null && update[i].forwords[i].data == value) { - update[i].forwords[i] = update[i].forwords[i].forwords[i]; + if (update[i].forwards[i] != null && update[i].forwards[i].data == value) { + update[i].forwards[i] = update[i].forwards[i].forwards[i]; } } } @@ -91,16 +91,16 @@ public class SkipList { public void printAll() { Node p = head; - while (p.forwords[0] != null) { - System.out.print(p.forwords[0] + " "); - p = p.forwords[0]; + while (p.forwards[0] != null) { + System.out.print(p.forwards[0] + " "); + p = p.forwards[0]; } System.out.println(); } public class Node { private int data = -1; - private Node forwords[] = new Node[MAX_LEVEL]; + private Node forwards[] = new Node[MAX_LEVEL]; private int maxLevel = 0; @Override