Skip to content

Commit

Permalink
Merge pull request wangzheng0822#125 from Liam0205/17_skiplist_typofix
Browse files Browse the repository at this point in the history
[java][17_skiplist] typo fix [forwords -> forwards]
  • Loading branch information
wangzheng0822 authored Nov 2, 2018
2 parents 92229ae + e484fe8 commit b0a8643
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions java/17_skiplist/SkipList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -45,15 +45,15 @@ public void insert(int value) {

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;
Expand All @@ -63,16 +63,16 @@ public void delete(int value) {
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];
}
}
}
Expand All @@ -91,16 +91,16 @@ private int randomLevel() {

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
Expand Down

0 comments on commit b0a8643

Please sign in to comment.