MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / construct

Method construct

animations/monostack.py:32–74  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

30 self.play(Transform(self.message, m))
31
32 def construct(self):
33 self.scale(1)
34 self.datas = [73, 74, 75, 71, 69, 72, 76, 73]
35 self.message = Text("单调栈", font=AlgoFontName).scale(0.5).shift(DOWN*1.5)
36 self.play(Write(self.message))
37
38 arr = AlgoVector(self, self.datas)
39 arr.to_edge(edge=UP)
40 for i in range(arr.size()):
41 arr.set_sub(i, str(i))
42
43 res = AlgoVector(self, [0, 0, 0, 0, 0, 0, 0, 0])
44 res.next_to(arr, direction=DOWN)
45 res.set_color("#666666")
46
47 stack = AlgoStack(self, [])
48
49 self.play(ShowCreation(arr))
50 self.play(ShowCreation(res))
51 self.play(ShowCreation(stack))
52
53 arrow = arr.add_arrow()
54
55 for i in range(arr.size()):
56 arr.move_arrow(arrow, i)
57
58 if not stack.empty():
59 self.compare(arr, i, stack.top_data())
60
61 while not stack.empty() and arr.get(i) > arr.get(stack.top_data()):
62 index = stack.top_data()
63 stack.pop()
64 self.wait()
65 res.set(index, i - index)
66 res.next_to(arr, direction=DOWN)
67 self.wait()
68 if not stack.empty():
69 self.compare(arr, i, stack.top_data())
70
71 stack.push(i)
72 self.wait()
73 self.show_message("完成单调栈,谢谢观看!")
74 self.wait(5)

Callers

nothing calls this directly

Calls 15

scaleMethod · 0.95
sizeMethod · 0.95
set_subMethod · 0.95
add_arrowMethod · 0.95
move_arrowMethod · 0.95
emptyMethod · 0.95
compareMethod · 0.95
top_dataMethod · 0.95
getMethod · 0.95
popMethod · 0.95
setMethod · 0.95
pushMethod · 0.95

Tested by

no test coverage detected