Skip to content

Commit

Permalink
improve red black bst & fix typoes
Browse files Browse the repository at this point in the history
  • Loading branch information
shellfly committed Dec 23, 2020
1 parent 5a95fdd commit eb99c7b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pip install algs4
```

```python
from algs4 import Stack
from algs4.stack import Stack
```

## Index
Expand Down
8 changes: 4 additions & 4 deletions algs4/edge_weighted_digraph.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
* Execution: python edge_weighted_graph.py filename.txt
* Execution: python edge_weighted_digraph.py filename.txt
* Data files: https://algs4.cs.princeton.edu/43mst/tinyEWG.txt
* https://algs4.cs.princeton.edu/43mst/mediumEWG.txt
* https://algs4.cs.princeton.edu/43mst/largeEWG.txt
*
* An edge-weighted undirected graph, implemented using adjacency lists.
* An edge-weighted directed graph, implemented using adjacency lists.
* Parallel edges and self-loops are permitted.
*
* % python edge_weighted_graph.py tinyEWD.txt
* % python edge_weighted_digraph.py tinyEWD.txt
* 8 vertices, 15 edges
* 0: 0->2 0.26000 0->4 0.38000
* 1: 1->3 0.29000
Expand Down Expand Up @@ -63,5 +63,5 @@ def edges(self):

if __name__ == "__main__":
import sys
graph = EdgeWeightedDiraph(file=open(sys.argv[1]))
graph = EdgeWeightedDigraph(file=open(sys.argv[1]))
print(graph)
2 changes: 1 addition & 1 deletion algs4/red_black_bst.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _delete_min(self, h):
return self.balance(h)

def balance(self, h):
if self.is_red(h):
if self.is_red(h) and not self.is_red(h.left):
h = self.rotate_left(h)
if self.is_red(h.left) and self.is_red(h.left.left):
h = self.rotate_right(h)
Expand Down

0 comments on commit eb99c7b

Please sign in to comment.