Skip to content

Commit eb99c7b

Browse files
committed
improve red black bst & fix typoes
1 parent 5a95fdd commit eb99c7b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pip install algs4
2020
```
2121

2222
```python
23-
from algs4 import Stack
23+
from algs4.stack import Stack
2424
```
2525

2626
## Index

algs4/edge_weighted_digraph.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
* Execution: python edge_weighted_graph.py filename.txt
2+
* Execution: python edge_weighted_digraph.py filename.txt
33
* Data files: https://algs4.cs.princeton.edu/43mst/tinyEWG.txt
44
* https://algs4.cs.princeton.edu/43mst/mediumEWG.txt
55
* https://algs4.cs.princeton.edu/43mst/largeEWG.txt
66
*
7-
* An edge-weighted undirected graph, implemented using adjacency lists.
7+
* An edge-weighted directed graph, implemented using adjacency lists.
88
* Parallel edges and self-loops are permitted.
99
*
10-
* % python edge_weighted_graph.py tinyEWD.txt
10+
* % python edge_weighted_digraph.py tinyEWD.txt
1111
* 8 vertices, 15 edges
1212
* 0: 0->2 0.26000 0->4 0.38000
1313
* 1: 1->3 0.29000
@@ -63,5 +63,5 @@ def edges(self):
6363

6464
if __name__ == "__main__":
6565
import sys
66-
graph = EdgeWeightedDiraph(file=open(sys.argv[1]))
66+
graph = EdgeWeightedDigraph(file=open(sys.argv[1]))
6767
print(graph)

algs4/red_black_bst.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _delete_min(self, h):
339339
return self.balance(h)
340340

341341
def balance(self, h):
342-
if self.is_red(h):
342+
if self.is_red(h) and not self.is_red(h.left):
343343
h = self.rotate_left(h)
344344
if self.is_red(h.left) and self.is_red(h.left.left):
345345
h = self.rotate_right(h)

0 commit comments

Comments
 (0)