@@ -68,59 +68,10 @@ without removing it from the stack.
6868
6969.. _stackdiag :
7070
71- .. blockdiag ::
72- :caption: Cartoon of a sequence of stack operations. First 24, 12, 57 are
73- pushed, then 57 is popped.
74-
75-
76- blockdiag stack{
77- // setup info
78- node_height = 30;
79- "Stack" [color = orange]; //push
80- "Stack " [color=orange, stacked]; //push
81- "Stack " [color=orange, stacked]; //push
82- "Stack " [color=orange, stacked]; //pop
83- "push 24" [color="#2E8B57"];
84- "push 12" [color="#2E8B57"];
85- "push 57" [color="#2E8B57"];
86- "pop" [color="#CD5C5C"];
87- group{
88- 24;
89- color = orange
90- }
91-
92- group second{
93- 12; "24 ";
94- color = orange
95- }
96-
97- group third{
98- 57 ;"12 "; "24 ";
99- color = orange
100- }
101-
102- group fourth{
103- "12 "; "24 ";
104- color = orange
105- }
106-
107- // structure and flow
108- "push 24" -> "Stack";
109- "push 24" -> 24 [style="none"];
110-
111- "push 12" -> "12" [style="none"];
112- "push 12" -> "Stack ";
113-
114- "push 57" -> "12 " [style="none"];
115- "push 57" -> "Stack ";
116-
117- "Stack" -> "pop" [style="none"];
118- "pop" -> "Stack ";
119- "pop" -> "12 "[style="none"];
120-
121- C [shape = "dots"]
122- "Stack " -> C [style="none"];
123- }
71+ .. figure :: images/stack.*
72+
73+ A sequence of stack operations. 24, 12, and 57. Finally the pop operation
74+ removes (and would return) 57.
12475
12576An example: reverse Polish notation
12677~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -209,6 +160,10 @@ While it is strictly true that Python does not have a stack type, the
209160:class: `list ` class functions as a perfectly good stack. The
210161relationship between the two is shown in :numref: `list_stack `.
211162
163+ .. raw :: latex
164+
165+ \clearpage
166+
212167.. _list_stack :
213168
214169.. list-table :: Correspondence between abstract stack operations, and
@@ -401,65 +356,13 @@ called a :term:`dynamic array`. :numref:`dynamicarray` illustrates its operation
401356
402357.. _dynamicarray :
403358
404- .. graphviz ::
405- :caption: A dynamic array implementation of a :class: `list `. The existing
406- memory buffer is full, so when 11 is appended to the list, a larger
407- buffer is created and the whole list is copied into it. When 13 is
408- subsequently appended to the list, there is still space in the buffer so
409- it is not necessary to copy the whole list.
410- :align: center
411-
412- digraph dl {
413- bgcolor="#ffffff00" # RGBA (with alpha)
414- graph [
415- rankdir = "LR"
416- ];
417- node [
418- fontsize = "16"
419- shape = "ellipse"
420- ];
421- edge [
422- ];
423-
424- subgraph cluster_0 {
425- style="ellipse, dashed";
426- bgcolor="#CD5C5C";
427- "node0" [
428- label = "<f0> 2 | 3| 5| 7 |e <f1>"
429- shape = "record"
430- ];
431- }
432-
433- subgraph cluster_3 {
434- style="ellipse, dashed";
435- bgcolor="#2E8B57";
436-
437- "node1" [
438- label = "<f0> 2 | 3| 5| 7 | <f1> 11| | | <f2>"
439- shape = "record"
440-
441- ];
442- }
443- subgraph cluster_4 {
444- style="ellipse, dashed";
445- bgcolor="#2E8B57";
446-
447- "node3" [
448- label = "<f0> 2 | 3| 5| 7| <f1> 11| <f2> 13| | <f3>"
449- shape = "record"
450- ];
451- }
452-
453- "node0":f0 -> "node1":f0 [
454- id = 2
455- label = "append 11"
456- ];
457-
458- "node1":f0 -> "node3":f0 [
459- id = 2
460- label = "append 13"
461- ];
462- }
359+ .. figure :: images/dynamic_array.*
360+
361+ A dynamic array implementation of a :class: `list`. The existing
362+ memory buffer is full, so when 11 is appended to the list, a larger
363+ buffer is created and the whole list is copied into it. When 13 is
364+ subsequently appended to the list, there is still space in the buffer so
365+ it is not necessary to copy the whole list.
463366
464367What does this memory allocation strategy mean for the computational
465368complexity of appending items to the list? There are two cases. If
0 commit comments