\begin{patch}{HeapXmpPagePatch1}
\begin{paste}{HeapXmpPageFull1}{HeapXmpPageEmpty1}
\pastebutton{HeapXmpPageFull1}{\hidepaste}
\tab{5}\spadcommand{h := heap [-4,9,11,2,7,-7]\bound{h }}
\indentrel{3}\begin{verbatim}
   (1)  [11, 9, - 4, 2, 7, - 7]
                                    Type: Heap(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty1}
\begin{paste}{HeapXmpPageEmpty1}{HeapXmpPagePatch1}
\pastebutton{HeapXmpPageEmpty1}{\showpaste}
\tab{5}\spadcommand{h := heap [-4,9,11,2,7,-7]\bound{h }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch2}
\begin{paste}{HeapXmpPageFull2}{HeapXmpPageEmpty2}
\pastebutton{HeapXmpPageFull2}{\hidepaste}
\tab{5}\spadcommand{insert!(3,h)\bound{h1 }\free{h }}
\indentrel{3}\begin{verbatim}
   (2)  [11, 9, 3, 2, 7, - 7, - 4]
                                    Type: Heap(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty2}
\begin{paste}{HeapXmpPageEmpty2}{HeapXmpPagePatch2}
\pastebutton{HeapXmpPageEmpty2}{\showpaste}
\tab{5}\spadcommand{insert!(3,h)\bound{h1 }\free{h }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch3}
\begin{paste}{HeapXmpPageFull3}{HeapXmpPageEmpty3}
\pastebutton{HeapXmpPageFull3}{\hidepaste}
\tab{5}\spadcommand{extract! h\bound{h2 }\free{h1 }}
\indentrel{3}\begin{verbatim}
   (3)  11
                                  Type: PositiveInteger
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty3}
\begin{paste}{HeapXmpPageEmpty3}{HeapXmpPagePatch3}
\pastebutton{HeapXmpPageEmpty3}{\showpaste}
\tab{5}\spadcommand{extract! h\bound{h2 }\free{h1 }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch4}
\begin{paste}{HeapXmpPageFull4}{HeapXmpPageEmpty4}
\pastebutton{HeapXmpPageFull4}{\hidepaste}
\tab{5}\spadcommand{h\free{h2 }}
\indentrel{3}\begin{verbatim}
   (4)  [9, 7, 3, 2, - 4, - 7]
                                    Type: Heap(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty4}
\begin{paste}{HeapXmpPageEmpty4}{HeapXmpPagePatch4}
\pastebutton{HeapXmpPageEmpty4}{\showpaste}
\tab{5}\spadcommand{h\free{h2 }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch5}
\begin{paste}{HeapXmpPageFull5}{HeapXmpPageEmpty5}
\pastebutton{HeapXmpPageFull5}{\hidepaste}
\tab{5}\spadcommand{[extract!(h) while not empty?(h)]\bound{h2 }}
\indentrel{3}\begin{verbatim}
   (5)  [9, 7, 3, 2, - 4, - 7]
                                    Type: List(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty5}
\begin{paste}{HeapXmpPageEmpty5}{HeapXmpPagePatch5}
\pastebutton{HeapXmpPageEmpty5}{\showpaste}
\tab{5}\spadcommand{[extract!(h) while not empty?(h)]\bound{h2 }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch6}
\begin{paste}{HeapXmpPageFull6}{HeapXmpPageEmpty6}
\pastebutton{HeapXmpPageFull6}{\hidepaste}
\tab{5}\spadcommand{heapsort(x) == (empty? x => []; cons(extract!(x),heapsort x))\bound{f }}
\indentrel{3}\begin{verbatim}
                                             Type: Void
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty6}
\begin{paste}{HeapXmpPageEmpty6}{HeapXmpPagePatch6}
\pastebutton{HeapXmpPageEmpty6}{\showpaste}
\tab{5}\spadcommand{heapsort(x) == (empty? x => []; cons(extract!(x),heapsort x))\bound{f }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch7}
\begin{paste}{HeapXmpPageFull7}{HeapXmpPageEmpty7}
\pastebutton{HeapXmpPageFull7}{\hidepaste}
\tab{5}\spadcommand{h1 := heap [17,-4,9,-11,2,7,-7]\bound{h1 }}
\indentrel{3}\begin{verbatim}
   (7)  [17, 2, 9, - 11, - 4, 7, - 7]
                                    Type: Heap(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty7}
\begin{paste}{HeapXmpPageEmpty7}{HeapXmpPagePatch7}
\pastebutton{HeapXmpPageEmpty7}{\showpaste}
\tab{5}\spadcommand{h1 := heap [17,-4,9,-11,2,7,-7]\bound{h1 }}
\end{paste}\end{patch}

\begin{patch}{HeapXmpPagePatch8}
\begin{paste}{HeapXmpPageFull8}{HeapXmpPageEmpty8}
\pastebutton{HeapXmpPageFull8}{\hidepaste}
\tab{5}\spadcommand{heapsort h1\free{f }}
\indentrel{3}\begin{verbatim}
   (8)  [17, 9, 7, 2, - 4, - 7, - 11]
                                    Type: List(Integer)
\end{verbatim}
\indentrel{-3}\end{paste}\end{patch}

\begin{patch}{HeapXmpPageEmpty8}
\begin{paste}{HeapXmpPageEmpty8}{HeapXmpPagePatch8}
\pastebutton{HeapXmpPageEmpty8}{\showpaste}
\tab{5}\spadcommand{heapsort h1\free{f }}
\end{paste}\end{patch}

