Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 752d1d7

Browse files
author
胡正伟
committed
iterator
1 parent 8c3e7d2 commit 752d1d7

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/ST/sequentialSearchST.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import assert from 'assert'
88

99
class Node {
1010
constructor(key, val, next) {
11-
this.key = key
12-
this.val = val
11+
this.key = key
12+
this.val = val
1313
this.next = next
1414
}
1515
}
@@ -33,9 +33,7 @@ class sequentialSearchST {
3333

3434
get(key) {
3535

36-
console.log(this)
3736
for (let node of this) {
38-
3937
if (key === node.key) {
4038
return node.val
4139
}
@@ -51,11 +49,11 @@ class sequentialSearchST {
5149
return ({
5250
next() {
5351
if (current) {
54-
let {key, val} = current
55-
current = current.next
52+
let node = current
53+
current = current.next
5654
return {
5755
done: false,
58-
val: {key, val}
56+
value: node
5957
}
6058
} else {
6159
return {
@@ -73,8 +71,9 @@ let st = new sequentialSearchST()
7371
assert.equal(st.get('a'), null)
7472
st.put('a', '1')
7573
assert.equal(st.get('a'), '1')
76-
//st.put('b', '2')
77-
//assert.equal(st.get('b'), '2')
78-
//st.put('b', '3')
79-
//assert.equal(st.get('a'), '1')
80-
//assert.equal(st.get('b'), '3')
74+
st.put('b', '2')
75+
assert.equal(st.get('b'), '2')
76+
st.put('b', '3')
77+
assert.equal(st.get('a'), '1')
78+
console.log(st.get('b'))
79+
assert.equal(st.get('b'), '3')

0 commit comments

Comments
 (0)