Skip to content

Commit

Permalink
add comment for sequential search st
Browse files Browse the repository at this point in the history
  • Loading branch information
shellfly committed Jan 31, 2020
1 parent eecc30e commit 2cdfd5c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Try to keep the interface and variable name consistent with the original book wh
* 3 SEARCHING

* [FrequencyCounter](algs4/frequency_counter.py)
* [SequentialSearchST](algs4/sequential_search.py)
* [SequentialSearchST](algs4/sequential_search_st.py)
* [BinarySearchST](algs4/binary_search_st.py)
* [BST](algs4/bst.py)
* [RedBlackBST](algs4/red_black_bst.py)
Expand Down
3 changes: 2 additions & 1 deletion algs4/separate_chaining_hash_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ def resize(self, chains):
tmp = SeparateChainingHashST(chains)
for i in range(self.m):
for key in self.st[i].keys():
tmp.put(key, st[i].get(key))
tmp.put(key, self.st[i].get(key))
self.m = tmp.m
self.n = tmp.n
self.st = tmp.st


if __name__ == '__main__':
import sys

Expand Down
39 changes: 39 additions & 0 deletions algs4/sequential_search_st.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
"""
* Execution: python3 sequential_search_st.py
* Data files: https://algs4.cs.princeton.edu/31elementary/tinyST.txt
*
* Symbol table implementation with sequential search in an
* unordered linked list of key-value pairs.
*
* % more tinyST.txt
* S E A R C H E X A M P L E
*
* % python3 sequential_search_st.py < tinyST.txt
* L 11
* P 10
* M 9
* X 7
* H 5
* C 4
* R 3
* A 8
* E 12
* S 0
*
"""


from algs4.utils.st import Node, STKeyIterator


Expand Down Expand Up @@ -51,3 +76,17 @@ def keys(self):

def is_empty(self):
return self.size == 0


if __name__ == '__main__':
import sys

st = SequentialSearchST()
i = 0
for line in sys.stdin:
for key in line.split():
st.put(key, i)
i += 1

for key in st.keys():
print(key + " " + str(st.get(key)))

0 comments on commit 2cdfd5c

Please sign in to comment.