Merge pull request #125 from Liam0205/17_skiplist_typofix
[java][17_skiplist] typo fix [forwords -> forwards]
This commit is contained in:
commit
b0a8643a34
@ -21,13 +21,13 @@ public class SkipList {
|
|||||||
public Node find(int value) {
|
public Node find(int value) {
|
||||||
Node p = head;
|
Node p = head;
|
||||||
for (int i = levelCount - 1; i >= 0; --i) {
|
for (int i = levelCount - 1; i >= 0; --i) {
|
||||||
while (p.forwords[i] != null && p.forwords[i].data < value) {
|
while (p.forwards[i] != null && p.forwards[i].data < value) {
|
||||||
p = p.forwords[i];
|
p = p.forwards[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.forwords[0] != null && p.forwords[0].data == value) {
|
if (p.forwards[0] != null && p.forwards[0].data == value) {
|
||||||
return p.forwords[0];
|
return p.forwards[0];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -45,15 +45,15 @@ public class SkipList {
|
|||||||
|
|
||||||
Node p = head;
|
Node p = head;
|
||||||
for (int i = level - 1; i >= 0; --i) {
|
for (int i = level - 1; i >= 0; --i) {
|
||||||
while (p.forwords[i] != null && p.forwords[i].data < value) {
|
while (p.forwards[i] != null && p.forwards[i].data < value) {
|
||||||
p = p.forwords[i];
|
p = p.forwards[i];
|
||||||
}
|
}
|
||||||
update[i] = p;
|
update[i] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < level; ++i) {
|
for (int i = 0; i < level; ++i) {
|
||||||
newNode.forwords[i] = update[i].forwords[i];
|
newNode.forwards[i] = update[i].forwards[i];
|
||||||
update[i].forwords[i] = newNode;
|
update[i].forwards[i] = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (levelCount < level) levelCount = level;
|
if (levelCount < level) levelCount = level;
|
||||||
@ -63,16 +63,16 @@ public class SkipList {
|
|||||||
Node[] update = new Node[levelCount];
|
Node[] update = new Node[levelCount];
|
||||||
Node p = head;
|
Node p = head;
|
||||||
for (int i = levelCount - 1; i >= 0; --i) {
|
for (int i = levelCount - 1; i >= 0; --i) {
|
||||||
while (p.forwords[i] != null && p.forwords[i].data < value) {
|
while (p.forwards[i] != null && p.forwards[i].data < value) {
|
||||||
p = p.forwords[i];
|
p = p.forwards[i];
|
||||||
}
|
}
|
||||||
update[i] = p;
|
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) {
|
for (int i = levelCount - 1; i >= 0; --i) {
|
||||||
if (update[i].forwords[i] != null && update[i].forwords[i].data == value) {
|
if (update[i].forwards[i] != null && update[i].forwards[i].data == value) {
|
||||||
update[i].forwords[i] = update[i].forwords[i].forwords[i];
|
update[i].forwards[i] = update[i].forwards[i].forwards[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,16 +91,16 @@ public class SkipList {
|
|||||||
|
|
||||||
public void printAll() {
|
public void printAll() {
|
||||||
Node p = head;
|
Node p = head;
|
||||||
while (p.forwords[0] != null) {
|
while (p.forwards[0] != null) {
|
||||||
System.out.print(p.forwords[0] + " ");
|
System.out.print(p.forwards[0] + " ");
|
||||||
p = p.forwords[0];
|
p = p.forwards[0];
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Node {
|
public class Node {
|
||||||
private int data = -1;
|
private int data = -1;
|
||||||
private Node forwords[] = new Node[MAX_LEVEL];
|
private Node forwards[] = new Node[MAX_LEVEL];
|
||||||
private int maxLevel = 0;
|
private int maxLevel = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user