Files
uni/third/semester1/CT331: Programming Paradigms/assignments/assignment3/latex/_minted-CT331-Assignment-3/F7B3D2A0A82F0DD8228307BD20745C9670E65A2BB389682C5F0235C03AA763AA.pygtex

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}