11 lines
1.2 KiB
Plaintext
11 lines
1.2 KiB
Plaintext
\begin{Verbatim}[commandchars=\\\{\}]
|
|
\PYG{c+c1}{\PYGZpc{} base fact: if the list is empty, the list to be returned is just the element}
|
|
\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[],} \PYG{p}{[}\PYG{n+nv}{Element}\PYG{p}{]).}
|
|
|
|
\PYG{c+c1}{\PYGZpc{} if the element to be inserted is \PYGZlt{}= the head of the list, insert it at the head of the list}
|
|
\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{p}{[}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nv}{Element} \PYG{o}{=\PYGZlt{}} \PYG{n+nv}{Head}\PYG{p}{.}
|
|
|
|
\PYG{c+c1}{\PYGZpc{} if the element to be inserted is greater than the head of the list, recurse with the tail of the list until}
|
|
\PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{Tail}\PYG{p}{],} \PYG{p}{[}\PYG{n+nv}{Head} \PYG{p}{|} \PYG{n+nv}{NewTail}\PYG{p}{])} \PYG{p}{:\PYGZhy{}} \PYG{n+nv}{Element} \PYG{o}{\PYGZgt{}} \PYG{n+nv}{Head}\PYG{p}{,} \PYG{n+nf}{insertInOrder}\PYG{p}{(}\PYG{n+nv}{Element}\PYG{p}{,} \PYG{n+nv}{Tail}\PYG{p}{,} \PYG{n+nv}{NewTail}\PYG{p}{).}
|
|
\end{Verbatim}
|