\chapter{MMIX} \begin{enumerate} \item {\bfseries Structures:} \begin{enumerate} \item MMIX Computer \item The Main \item LOC \item GREG \item Instructions Labels \item Argc and Argv; $0,$1 \item Trap 0,Halt,0 \end{enumerate} \item {\bfseries First Stage:} \begin{enumerate} \item Pseudo Settings \item Additions \item Subtractions \item Multiplications \item Divisions \item Overflows \item Negations \item Comparisons \item Taking From Specials \end{enumerate} \item {\bfseries Memory Communication} \begin{enumerate} \item Assembly Puts \item Reading From Memory \item Saving Back To The Memory \item One weird piece \item Increase Readability \end{enumerate} \item {\bfseries Inputs, Outputs} \begin{enumerate} \item Pseudo Loading \item I/Os \end{enumerate} \item {\bfseries Jumping Around} \begin{enumerate} \item Relative Jumps \item Getting Forward Addresses \item Absolute Jumps \item Conditional Statements \item Local Labels \item Conditional Assignements \end{enumerate} \item {\bfseries SubRoutines} \begin{enumerate} \item Foreground \item Prefixing \item Pushing The Stack \item Poping The Stack \end{enumerate} \item {\bfseries Data Structures} \begin{enumerate} \item Gating Eg: \item BitShifting \item 2Bytes Setting \item Miscallenous \item Addressing \end{enumerate} \item Floating Numbers \begin{enumerate} \item Floating Introduction \item Conversions \item Arithmetic \item Comparisons \item Short Float Conversions \item Loading and storing of short floats \end{enumerate} \item Fields \begin{enumerate} \item Address Calculation nice \end{enumerate} \item Graphics \item Bitmap \item Some more \end{enumerate} Taking From Special Registers

[The following registers cannot be written to: rC, rL, rN, rD, rS, rI, rT, rTT, rK, rQ, rU and rV. No value can be written to rG that is smaller than 32 (or lower than the value currently contained in rL) or greater than 255. No value can be written to rA that is greater than \#3FFFF]

 Expressions
[considered as octabytes]
\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{expressions.png}
[\$ allowed only as regi+pure, pure+reg, reg-pure, reg-reg while weak binary cant be on reg,reg gives reg no while the last just give pure value as \$ get canceled]

\end{figure} \section{Control Unit} [actually the commands are carried out in many different steps controlled by control unit, the control unit has command register that has the address of the next command. It has a PC register that store the memory address of the next instruction to be carried out and instruction register that includes the command in encoded form]

\begin{enumerate} \item Good guys sympathize \item Interreuptions

$$[program,timer,i/o,hardware failure: control jumps from the program to interrupt handler of OS (trap),or of user(trip)]$$

\end{enumerate} \chapter{Information Structures} \section{Prerequisites} \begin{enumerate} \item Terminology:\par [The information in a list consists of a set of nodes, each of which consists of one or more consecutive words of the computer memory, divided into named parts called fields, meanwhile the memory address of a node, taken relative to a base location is called link to that node] \item Notations:\par \begin{center} \begin{itemize} \item {[Referring to fields within a node:]} \item {[Denoting a whole node:]} \item {[Converting between addresses and values stored of a node:]} \end{itemize} \end{center} \end{enumerate} \section{Linear Lists} \begin{enumerate} \item Definition:\par [A linear list is a sequence of nodes] [whose essential properties involve only the relative positions between items as they appear in a line that] \begin{itemize} \item {[if , is the first node and is the last]} \item {[if , is preceded by and followed by ]} \end{itemize} \item Desired Operations:\par \begin{enumerate} \item {[Gain access to the kth node of the list to examine and/or to change the contents of its fields]} \item {[Insert a new node just before or after the kth node]} \item {[Delete the kth node]} \item {[Combine two or more linear lists into a single list]} \item {[Split a linear list into two or more lists]} \item {[Make a copy of a linear list]} \item {[Determine the number of nodes in a list]} \item {[Sort the nodes of the list into ascending order based on certain fields of the nodes]} \item {[Search the list for the occurrence of a node with a particular value in some field]} \end{enumerate} \item Special Names:\par [Linear lists in which insertions, deletions, and accesses to values occur almost always at the first or the last node are very frequently encountered] \begin{itemize} \item {[A stack is a linear list for which all insertions and deletions (and usually all accesses) are made at one end of the list (FIFO)]} \item {[A queue is a linear list for which all insertions are made at one end of the list; all deletions (and usually all accesses) are made at the other end (LIFO)]} \item {[A deque (“double-ended queue”) is a linear list for which all insertions and deletions (and usually all accesses) are made at the ends of the list]} \end{itemize} \item Stacks’ Applications: \begin{itemize} \item {[problem solving approach]} \item {[entering and exiting the subroutines]} \item {[processing of languages with nested structures]} \item {[recursive algorithms]} \end{itemize} \end{enumerate} \subsection{Sequential Allocation} \begin{enumerate} \item Principles \item Stacks [First Draft: Pointer T]: \item Queues [First Draft: Pointer F and R]: \item Queues [Second Draft: X[1] follows X[M]] \item Stacks [Second Draft: Memory Restrictions]

\text{T}\leftarrow \text{T}+1;\\ \text{if }\text{T}>\text{M},\text{ then OVERFLOW};\\ \text{X[T]}\leftarrow \text{Y}; \end{array}\right.\right]$$ $$\left[\text{Y}\Leftarrow \text{X}:~\left\{\begin{array}{l} \text{if }\text{T}=0,\text{ then UNDERFLOW};\\ \text{Y}\leftarrow \text{X[T]};\\ \text{T}\leftarrow \text{T}-1; \end{array}\right.\right]$$ \item Queues [Third Draft: IS- F $=$ R $=1$] $$\left[\text{X}\Leftarrow \text{Y}:~\left\{\begin{array}{l} \text{if }\text{R}=\text{M}\text{ then }\text{R}\leftarrow 1\text{ else: }\text{R}\leftarrow \text{R}+1;\\ \text{if }\text{R}=\text{F},\text{ then OVERFLOW};\\ \text{X[R]}\leftarrow \text{Y}; \end{array}\right.\right]$$ $$\left[\text{Y}\Leftarrow \text{X}:~\left\{\begin{array}{l} \text{if }\text{F}=\text{R},\text{ then UNDERFLOW};\\ \text{if }\text{F}=\text{M}\text{ then }\text{F}\leftarrow 1\text{ else: }\text{F}\leftarrow \text{F}+1;\\ \text{Y}\leftarrow \text{X[F]}; \end{array}\right.\right]$$ \item Deques [Additionals] $$\left[\text{X}\Leftarrow \text{Y}:~\left\{\begin{array}{l} \text{X[F]}\leftarrow \text{Y};\\ \text{if }\text{F}=\text{1}\text{ then }\text{F}\leftarrow \text{M}\text{ else: }\text{F}\leftarrow \text{F}-1;\\ \text{if }\text{F}=\text{R},\text{ then OVERFLOW}; \end{array}\right.\right]$$ $$\left[\text{Y}\Leftarrow \text{X}:~\left\{\begin{array}{l} \text{if }\text{R}=\text{F},\text{ then UNDERFLOW};\\ \text{Y}\leftarrow \text{X[R]};\\ \text{if }\text{R}=\text{1}\text{ then }\text{R}\leftarrow \text{M}\text{ else: }\text{R}\leftarrow \text{R}-1; \end{array}\right.\right]$$ \item Counters [The Overflow]\par {[Two variable-size lists can coexist together if let them grow toward each other while]} \item n Stacks [L:L$_0$-L$_\infty$,~Link- BASE$[i]$ and TOP$[i]$] \begin{enumerate} \item Initialization: $$[\text{BASE}[j]=\text{TOP}[j]=\text{L}_0~\text{for }1\le j\le n,~ \text{BASE}[n+1]=\text{L}_\infty]$$ $$\left[\text{BASE}[j] = \text{TOP}[j] = \left\lfloor\left(\frac{j-1} {n}\right)\Delta \text{L}\right\rfloor +\text{L}_0 \text{ for } 1 \le j \le n,~ \text{BASE}[n+1]=\text{L}_\infty]\right]$$ \item Operations: $$\left[\text{X}\Leftarrow \text{Y}:~\left\{\begin{array}{l} \text{TOP}[i]\leftarrow \text{TOP}[i]+1;\\ \text{if }\text{TOP}[i]>\text{BASE}[i+1],\text{ then OVERFLOW};\\ \text{CONTENTS}(\text{TOP}[i])\leftarrow \text{Y}; \end{array}\right.\right]$$ $$\left[\text{Y}\Leftarrow \text{X}:~\left\{\begin{array}{l} \text{if }\text{TOP}[i]=\text{BASE}[i],\text{ then UNDERFLOW};\\ \text{Y}\leftarrow \text{CONTENTS(\text{TOP}[i])};\\ \text{TOP}[i]\leftarrow \text{TOP}[i]-1; \end{array}\right.\right]$$ \item 1st Possibility [Notch]: \begin{enumerate} \item {[Find the smallest $k$ for which $i < k \le n$ and TOP$[k]$ $<$ BASE$[k + 1]$;]} $$[\text{CONTENTS}(\text{L}+1)\leftarrow \text{CONTENTS}(\text{L}),\text{ for } \text{TOP}[k]\ge \text{L}>\text{BASE}[i+1];]$$ (This must be done for decreasing values of L) (It is possible that TOP$[k] = $ BASE$[i + 1]$, in which case nothing needs to be moved) $$[\text{BASE}[j] \leftarrow \text{BASE}[j] + 1, \text{TOP}[j]\leftarrow \text{TOP}[j] + 1, \text{for } i < j \le k;]$$ \item {[No k in $(a)$, find the largest k for which $1 \le k < i$ and TOP$[k] < $ BASE$[k + 1]$;]} $$[\text{CONTENTS}(\text{L} -1)\leftarrow \text{CONTENTS}(\text{L}),\text{ for BASE}[k + 1] < \text{L} < \text{TOP}[i];]$$ (This must be done for increasing values of L.) $$[\text{BASE}[j]\leftarrow \text{BASE}[j] -1, \text{TOP}[j]\leftarrow \text{TOP}[j] -1,\text{ for } k < j \le i;]$$ \item {[No $k$ in $(b)$ that is TOP$[k] = $ BASE$[k + 1]$ for all $k \ne i$, EXIT;]} \end{enumerate} \item 2nd Possibility [Reallocation]:\par {\bfseries Algorithm G:} \begin{enumerate} \item Assests:\par {[An array OLDTOP$[j]$, retains TOP$[j]$ just after the previous allocation of memory]} \item {[Initialize]} $$[\text{SUM} \leftarrow \text{L}_\infty - \text{L}_0;\text{ INC}\leftarrow 0;]$$ (The effect will be to make SUM equal to the total amount of memory space left, and INC equal to the total amount of increases in table sizes since the last allocation) \item {[Gather statistics.]} $$[\text{For }1 \le j \le n:~ \text{SUM} \leftarrow \text{SUM} -(\text{TOP}[j]-\text{BASE}[j]);\ldots]$$ $$[\ldots\text{if TOP}[j] > \text{OLDTOP}[j]: \text{D}[j]\leftarrow \text{TOP}[j]-\text{OLDTOP}[j],~\text{INC} \leftarrow \text{INC}+\text{D}[j];\ldots]$$ $$[\ldots\text{else: D}[j]\leftarrow 0;]$$ \item {[Is memory full?]} $$[\text{if SUM $< 0$: EXIT;}]$$ \item {[Compute allocation factors.]} $$\left[\alpha[\text{10\%}] \leftarrow 0.1 \times \frac{\text{SUM}}{n};~\beta[\text{90\%}] \leftarrow 0.9 \times \frac{\text{SUM}}{\text{INC}};\right]$$ (Approximately 10 percent of the memory presently available will be shared equally among the n lists, and the other 90 percent will be divided proportionally to the amount of increase in table size since the previous allocation) \item {[Compute new base addresses.]} $$[\text{NEWBASE}[1]\leftarrow \text{BASE}[1];~ \sigma[\text{offset}]\leftarrow 0;]$$ $$[\text{For } j = 2, 3, \ldots, n:~ \tau[\text{continuous increment}] \leftarrow \sigma + \alpha + \text{D}[j-1]\beta,\ldots]$$ $$[\ldots\text{NEWBASE}[j]\leftarrow \text{NEWBASE}[j-1]+\text{TOP}[j-1]-\text{BASE}[j-1] +\lfloor\tau\rfloor-\lfloor\sigma\rfloor,]$$ $$[\sigma\leftarrow \tau;]$$ \item {[Repack.]} $$[\text{TOP}[i] \leftarrow \text{TOP}[i]-1;]$$ (This reflects the true size of the $i$th list)\par [Perform R; then] $$[\text{TOP}[i] \leftarrow \text{TOP}[i] + 1;]$$ $$[\text{OLDTOP}[j] \leftarrow \text{TOP}[j] \text{ for } 1\le j \le n;]$$ {\bfseries Algorithm R:} \item {[Initialize]} $$[j\leftarrow 1;]$$ \item {[Find start of shift.]} \par (Now all lists from $1$ to $j$ to be moved down have been shifted into desired position)\par [Increase $j$ in steps of $1$ until finding either] $$[\text{NEWBASE}[j] <\text{BASE}[j]:\text{ Go to R3;}]$$ $$[j > n:\text{ Go to R4; or}]$$ \item {[Shift list down.]} $$[\delta\leftarrow \text{BASE}[j]-\text{NEWBASE}[j];]$$ $$[\text{CONTENTS}(\text{L}-\delta)\leftarrow \text{CONTENTS}(\text{L}),\text{ for }\text{L} = \text{BASE}[j]+1, \text{BASE}[j]+2, ...,\text{TOP}[j];]$$ (It is possible for BASE$[j]$ to equal TOP$[j]$, in which case no action is required) $$[\text{BASE}[j]\leftarrow\text{NEWBASE}[j]; \text{ TOP}[j] \leftarrow\text{TOP}[j]-\delta;]$$ $$[\text{Go back to R2;}]$$ \item {[Find start of shift.]}\par (Now all lists from $j$ to $n$ to be moved up have been shifted into desired position)\par [Decrease $j$ in steps of $1$; until finding either] $$[\text{NEWBASE}[j] > \text{BASE}[j]: \text{Go to R5; or}]$$ $$[j = 1: \text{TERMINATE;}]$$ \item {[Shift list up.]} $$[\delta\leftarrow \text{NEWBASE}[j]-\text{BASE}[j];]$$ $$[\text{CONTENTS}(\text{L}+\delta)\leftarrow \text{CONTENTS}(\text{L}),\text{ for }\text{L} = \text{TOP}[j], \text{TOP}[j]-1, ...,\text{BASE}[j]+1;]$$ (As in R3, no action may actually be needed here) $$[\text{BASE}[j]\leftarrow\text{NEWBASE}[j]; \text{TOP}[j] \leftarrow\text{TOP}[j]+\delta;]$$ $$[\text{Go back to R4;}]$$ \end{enumerate} (The stack 1 never needs to be moved therefore, put the largest stack first) (Purposely made it possible to have $$[\text{OLDTOP}[j]\equiv D[j]\equiv\text{NEWBASE}[j + 1]\text{ for }1 \le j \le n]$$ that is, these three tables can share common memory locations since their values are never needed at conflicting times) \end{enumerate} \end{enumerate} \subsection{Linked Allocation} \begin{enumerate} \item Comparison With Sequential \begin{enumerate} \item {[Assessment]} To gain access to the kth item in the list, when k is a variable, takes a fixed time in the sequential case, but we need k iterations to march down to the right place in the linked case] \item {[Memory]} Implicit gain in storage by the linked memory approach, since tables can overlap, sharing common parts; and in many cases, sequential allocation will not be as efficient as linked allocation unless a rather large number of additional memory locations are left vacant anyway. \item {[Deletion]} It is easy to delete an item from within a linked list by only changing the link associated with an item but with sequential allocation such a deletion generally implies moving a large part of the list up into different locations. \item {[Insertion]} It is easy to insert an item into the midst of a list when the linked scheme is being used by changing only two links \item {[Joining Or Breaking]} The linked scheme makes it easier to join two lists together, or to break one apart into two that will grow independently. \end{enumerate} \item Available Space [AVAIL Pointer] $$[\text{Empty AVAIL: AVAIL}=\Lambda]$$ $$[\text{X}\Leftarrow\text{AVAIL}:~ \text{if AVAIL}= \Lambda,\text{ then OVERFLOW; else: X}\leftarrow\text{ AVAIL, AVAIL} \leftarrow\text{LINK(AVAIL)};]$$ $$[\text{AVAIL}\Leftarrow \text{X: }\text{LINK(X)}\leftarrow \text{AVAIL}; \text{AVAIL} \leftarrow \text{X};]$$ \item Make AVAIL [L:L$_0$-SEQMIN; POOLMAX] $$[\text{Initially, AVAIL}\leftarrow \Lambda \text{; POOLMAX} \leftarrow\text{L}_0;]$$ $$[\text{X}\Leftarrow\text{AVAIL}:]$$ $$[\text{if AVAIL}\ne\Lambda,\text{ then X}\leftarrow\text{AVAIL, AVAIL}\leftarrow\text{LINK(AVAIL)};\ldots]$$ $$[\ldots\text{else: X }\leftarrow\text{POOLMAX, POOLMAX }\leftarrow\text{X} + 1;]$$ $$[\text{if POOLMAX} > \text{SEQMIN:}\text{ OVERFLOW};]$$ \item Stacks $$[\text{Empty Stack: }\text{T}=\Lambda]$$ $$[\text{X}\Leftarrow\text{Y:~}\text{P}\Leftarrow\text{AVAIL; INFO(P)}\leftarrow\text{Y; LINK(P)}\leftarrow\text{T; T}\leftarrow\text{P}]$$ $$[\text{Y}\Leftarrow\text{X}:]$$ $$[\text{if T}= \Lambda,\text{ then UNDERFLOW; else: P} \leftarrow\text{T, T}\leftarrow\text{LINK(P), Y}\leftarrow\text{INFO(P), AVAIL}\Leftarrow\text{P};]$$ $$\text{**Permutation Observation Goes Here**}$$ (Insertion, is performed just before the node pointed to by link variable T.) \item Queues $$\text{**Linked List In Midst of Isertion And Deletion Goes Here**}$$ $$[\text{X}\Leftarrow \text{Y}:~\text{P}\Leftarrow\text{AVAIL; INFO(P)}\leftarrow\text{Y; LINK(P)}\leftarrow \Lambda;\text{ LINK(R)}\leftarrow\text{P; R}\leftarrow\text{P};]$$ $$\text{*Single Node In Link List Goes Here*}$$ $$[\text{Empty Queue: F}=\Lambda, \text{R}=\text{LOC(F): F}=\text{LINK(R)} ]$$ $$[\text{Y}\Leftarrow \text{X}:~\text{if F}=\Lambda, \text{then UNDERFLOW; else: P}\leftarrow \text{F; F}\leftarrow\text{LINK(P); Y}\leftarrow\text{INFO(P); AVAIL}\Leftarrow\text{P};]$$ $$[\text{ if F}=\Lambda,\text{then R}\leftarrow\text{LOC(F)};]$$ \item Topological Sort \begin{enumerate} \item Partial Ordering:\par [A partial ordering of a set S is a relation between the objects of S, satisfying the following properties for any objects x, y, and z in S] \begin{enumerate} \item {[If x $\preceq$ y and y $\preceq$ z, then x $\preceq$ z. (Transitivity)]} \item {[If x $\preceq$ y and y $\preceq$ x, then x $=$ y. (Antisymmetry)]} \item {[x $\preceq$ x. (Reflexivity)]} \end{enumerate} [or equivalently] \begin{enumerate} \item {[If x $\prec$ y and y $\prec$ z, then x $\prec$ z. (Transitivity)]} \item {[If x $\prec$ y, then y $\nprec$ x. (Asymmetry)]} \item {[x $\nprec$ x. (Irreflexivity)]} $$\text{*Graphical Partial Order Goes Here*}$$ \end{enumerate} \item Principle\par {[The problem is to embed the partial order in a linear order; that is, to arrange the objects of set S into a linear sequence $\text{a}_1\text{a}_2\ldots \text{a}_n$ such that whenever $\text{a}_j\prec \text{a}_k$, there is $j < k$]} $$\text{*Sorting Of The Graphical Partial Order Goes Here*}$$ \item Applications \begin{itemize} \item {[chronology of jobs]} \item {[glossary containing definition of technical terms as one depends on other]} \item {[declarations processing and assembly and compiler languages]} \end{itemize} \item Ideas \begin{enumerate} \item {[The first object in output is that which is not preceded by any other object in the ordering which is then removed from the set S; the resulting set is again partially ordered, and the process can be repeated until the whole set has been sorted]} \item Input: \par [$(0,n)$ where $n$ is number of objects, 256 pairs of TETRAs of objects numbered from $1$ to $n$, where the pair $(j, k)$ means that object $j$ precedes object $k$, $(0,0)^*$] \item Output:\par [numbers of the objects in sorted order, followed by the number 0] \end{enumerate} (It is not necessary to give any more relations than are needed to characterize the desired partial ordering thus, additional relations may be omitted from or added to the input without harm)\par {\bfseries Algorithm T:} \begin{enumerate} \item Assests:\par [A sequential table $X[0], X[1], . . . , X[n]$ where each node $X[k]$ has the form] $$[[\text{COUNT}[k][\text{TETRA}],~ \text{TOP}[k][\text{TETRA}]]$$ $$[\text{no of predecessors}], \text{[link to the beginning of the list of direct successors]}]$$ [The latter list contains entries in the format] $$\text{[SUC[\text{TETRA}],~NEXT[\text{TETRA}]]}$$$$\text{[[direct successor of k],[next item of the list]]}$$ (All addresses are relative to a fixed global address Base and can be converted into an absolute address by adding Base) $$\text{*Schematic Memory Structure Of Graphical Order Goes Here*}$$ [The nodes whose COUNT field is zero are put on the output, then decreased the COUNT fields of all successors of those nodes, by avoiding any searching, through maintaining a queue containing those nodes whose links are kept in the COUNT field, as QLINK[k], which by then would have served its previous purpose] \item {[Initialize.]} $$[\text{COUNT}[k]\leftarrow 0,~\text{TOP}[k]=\Lambda\text{ for }1\le k\le n;~N[\text{objects yet to output}]\leftarrow n;]$$ \item {[Next relation.]}\par [Get the next $"j \prec k"$ from input; if the input has been exhausted, however, go to T4;] \item {[Record the relation.]}\par [Increase \text{COUNT}$[k]$ by one;] $$[\text{P}[\text{temp link}]\Leftarrow \text{AVAIL, SUC(P)}\leftarrow k, \text{ NEXT(P)}\leftarrow \text{TOP}[j],\text{ TOP}[j]\leftarrow \text{P}]$$ [Go back to T2;] \item {[Scan for zeros.]}\par (At this point the input phase has been completed; the input would now have been transformed into the computer representation, now is to initialize the queue of output, which is linked together in the QLINK field) $$[\text{R}[\text{web needle}]\leftarrow 0;\text{ QLINK}[0] \leftarrow 0]$$ $$[\text{For }1 \le k \le n: \text{ if } \text{COUNT}[k]=0:\text{QLINK[R]} \leftarrow k;\text{ R} \leftarrow k]$$ $$[\text{F[first k of the link]}\leftarrow\text{ QLINK}[0]]$$ \item {[Output front of queue.]} \par {[Output the value of F;]} $$[\text{if F} = 0,\text{ go to T8; else: } N\leftarrow N - 1,\text{ P }\leftarrow\text{TOP[F]};]$$ \item {[Erase relations.]} $$[\text{if P} = \Lambda,\text{ go to T7 else: decrease } \text{COUNT[SUC(P)]} \text{ by one;}]$$ (and if it has thereby gone down to zero) $$[\text{QLINK[R]}\leftarrow \text{SUC(P), R}\leftarrow\text{SUC(P)};]$$ $$[\text{P}\leftarrow\text{NEXT(P);}]$$[Repeat this step;]\par (This removes all relations of the form $"\text{F}\prec k"$ for some $k$ from the system, and puts new nodes into the queue when all their predecessors have been output) \item {[Remove from queue.]} $$[\text{F}\leftarrow\text{QLINK[F];}]$$ [Go back to T5;] \item {[End of process.]} $$[\text{if N}=0,\text{ then TERMINATE; else: EXIT}]$$ \end{enumerate} \end{enumerate} \end{enumerate} \subsection{More Links} \subsubsection{Circular Lists} \begin{enumerate} \item Principles\par {[A circularly linked list has the property that its last node links back to the first instead of to $\Lambda$ then it is then possible to access all of the list starting at any given point; with an extra degree of symmetry]} $$\text{*Graphical Links Connected*}$$ \item Primitives $$[\text{Empty: PTR}=\Lambda]$$ $$[\text{X}_\text{LEFT}\Leftarrow\text{Y} :\text{P}\Leftarrow\text{AVAIL; INFO(P)}\leftarrow\text{Y;}]$$ $$[\text{if PTR} = \Lambda,\text{ then PTR}\leftarrow\text{LINK(P)}\leftarrow\text{P; else: LINK(P)}\leftarrow\text{LINK(PTR), LINK(PTR)}\leftarrow\text{P};]$$ $$[\text{Y}_\text{RIGHT}\Leftarrow\text{X}:\text{X}_\text{LEFT}\Leftarrow\text{Y};\text{ PTR}\leftarrow\text{P};]$$ $$[\text{Y}\Leftarrow\text{X}:\text{if PTR} = \Lambda,\text{ then UNDERFLOW};]$$ $$[\text{P}\leftarrow\text{LINK(PTR); Y}\leftarrow\text{INFO(P); LINK(PTR)}\leftarrow \text{LINK(P); AVAIL }\Leftarrow\text{P};]$$ $$[\text{ if PTR} =\text{ P, then PTR}\leftarrow \Lambda;]$$ (A circular list can be used as either a stack or a queue as operations (a) and (c) combined give a stack; operations (b) and (c) give a queue) \item Destruction $$[\text{if PTR}\ne \Lambda,\text{ then P}\leftarrow\text{ AVAIL, AVAIL}\leftarrow \text{LINK(PTR), LINK(PTR)}\leftarrow\text{P}, \text{PTR}\leftarrow \Lambda;]$$ (This operation is clearly valid if PTR points anywhere in the circular list) \item Concatenation\par (if PTR1 and PTR2 point to disjoint circular lists L1 and L2, respectively, inserts list L2 at the right of L1) $$[\text{if PTR2}\ne \Lambda,\text{ then:}]$$ $$[\text{if PTR1}\ne \Lambda,\text{ then LINK(PTR1)}\leftrightarrow \text{LINK(PTR2);}]$$ $$[\text{PTR1}\leftarrow\text{PTR2};\text{ PTR2} \leftarrow \Lambda;]$$ \item Alternatives\par {[An alternative solution is to put a special, recognizable node called the list head, into each circular list, as a convenient stopping place so the circular list will then never be empty]} \item Polynomials\par [A polynomial is represented as a list in which each node stands for one nonzero term, and has the three-octabyte form: $$[\text{LINK;~SIGN,~A,~B,~C;~COEF}]$$ [The SIGN field will always be zero, except that there is a special node at the end of every polynomial that has ABC = -1 and COEF = 0, which links to the largest value of ABC as the nodes always appear in decreasing order of ABC field] $$\text{[*Polynomials Links*]}$$ {\bfseries Algorithm A}\par (The list P will be unchanged; the list Q will retain the sum, pointer variables P and Q return to their starting points at the conclusion of this algorithm; auxiliary pointer variables Q1 and Q2 are also used) \begin{enumerate} \item {[Initialize.]}$$[\text{P}\leftarrow\text{LINK(P); Q1}\leftarrow\text{Q; Q}\leftarrow\text{LINK(Q);}]$$ (Now both P and Q point to the leading terms of their polynomials, throughout most of this algorithm the variable Q1 will be one step behind Q, in the sense that Q = LINK(Q1)) \item {[Add coefficients.]} (We’ve found terms with equal exponents.) If ABC(P) <0, the algorithm terminates. Otherwise set COEF(Q) ← COEF(Q) + COEF(P). Now if COEF(Q) = 0, go to A4; otherwise, set P ← LINK(P), Q1 ← Q, Q ← LINK(Q), and go to A2. (Curiously the latter operations are identical to step A1.) \item {[Delete zero term.]} Set Q2 ← Q, LINK(Q1) ← Q ← LINK(Q), and AVAIL $\Leftarrow$ Q2. (A zero term created in step A3 has been removed from polynomial(Q).) Set P ←LINK(P) and go back to A2. \item {[Insert new term.]} (Polynomial(P) contains a term that is not present in polynomial(Q), so we insert it in polynomial(Q).) Set Q2 $\Leftarrow$ AVAIL, COEF(Q2) ←COEF(P), ABC(Q2) ←ABC(P), LINK(Q2) ←Q, LINK(Q1) ←Q2, Q1 ←Q2, P ←LINK(P), and return to step A2. \end{enumerate} \end{enumerate} \subsubsection{Doubly Linked Lists} \end{document}