Skip to content

Commit 0d259e0

Browse files
author
Philip Guo
committed
added some strays
1 parent 3de10c9 commit 0d259e0

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎v3/bst_test.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from bintree_module import BST
2+
import html_module
3+
import random
4+
5+
t = BST()
6+
html_module.display_img(t.to_graphviz_img())
7+
8+
nums = [e for e in range(10)]
9+
random.shuffle(nums)
10+
for i in nums:
11+
t.insert(i)
12+
html_module.display_img(t.to_graphviz_img())

‎v3/selection_sort_watch.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# created by Peter Norvig
2+
from watch_module import watchfn, watchedlist
3+
4+
# The decorator here says that the 0th positional argument should be a list;
5+
# we will watch it, and the locals named i, mini, and min_index
6+
@watchfn((watchedlist, 'i mini min_index'))
7+
def selection_sort(A):
8+
for i in range(len(A)): #break
9+
mini = min(A[i:])
10+
min_index = A[i:].index(mini) + i
11+
if i != min_index:
12+
A[min_index], A[i] = A[i], A[min_index]
13+
return A
14+
15+
print(selection_sort([3, 5, 2, 1, 8, 5, 9]))

0 commit comments

Comments
 (0)