\hypertarget{stack_8c}{
\section{stack.c File Reference}
\label{stack_8c}\index{stack.c@{stack.c}}
}
Stack manipulation functions. 

{\tt \#include \char`\"{}XLX\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}stdlib.h\char`\"{}}\par
{\tt \#include \char`\"{}string.h\char`\"{}}\par
{\tt \#include \char`\"{}stdio.h\char`\"{}}\par


Include dependency graph for stack.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=149pt]{stack_8c__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned \hyperlink{stack_8c_a0}{XLX\_\-init\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, unsigned int limit)
\begin{CompactList}\small\item\em Initialise a stack by allocating memory to hold the contents and setting limit and used. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a1}{XLX\_\-end\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Free the memory allocated to the stack. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a2}{XLX\_\-destroy\-Stack} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, \hyperlink{XLX_8h_a5}{XLX\_\-p\-Delete} d\-Fn)
\begin{CompactList}\small\item\em Free the memory allocated to the stack and its elements. \item\end{CompactList}\item 
unsigned \hyperlink{stack_8c_a3}{XLX\_\-push} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack, void $\ast$ptr)
\begin{CompactList}\small\item\em Put a new item on the top of the stack and increment the counter, doubling the size of the stack if the stack is already full. \item\end{CompactList}\item 
void $\ast$ \hyperlink{stack_8c_a4}{XLX\_\-pop} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Remove and return the top item on the stack. \item\end{CompactList}\item 
void $\ast$ \hyperlink{stack_8c_a5}{XLX\_\-peek} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Look at the item on the top of the stack without removing it. \item\end{CompactList}\item 
void \hyperlink{stack_8c_a6}{XLX\_\-dump} (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$stack)
\begin{CompactList}\small\item\em Print out the stack information. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Stack manipulation functions. 

\begin{Desc}
\item[Author:]James Swain \& Owen Saxton\end{Desc}
\begin{Desc}
\item[Id]\hyperlink{stack_8c}{stack.c},v 1.7 2006/09/18 18:02:43 saxton Exp \end{Desc}


\subsection{Function Documentation}
\hypertarget{stack_8c_a2}{
\index{stack.c@{stack.c}!XLX_destroyStack@{XLX\_\-destroyStack}}
\index{XLX_destroyStack@{XLX\_\-destroyStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-destroyStack]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-destroy\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, \hyperlink{XLX_8h_a5}{XLX\_\-p\-Delete} {\em d\-Fn})}}
\label{stack_8c_a2}


Free the memory allocated to the stack and its elements. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to end\item[{\em d\-Fn}]Function to call to delete objects on the stack\end{description}
\end{Desc}
\hypertarget{stack_8c_a6}{
\index{stack.c@{stack.c}!XLX_dump@{XLX\_\-dump}}
\index{XLX_dump@{XLX\_\-dump}!stack.c@{stack.c}}
\subsubsection[XLX\_\-dump]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-dump (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a6}


Print out the stack information. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to dump\end{description}
\end{Desc}
\hypertarget{stack_8c_a1}{
\index{stack.c@{stack.c}!XLX_endStack@{XLX\_\-endStack}}
\index{XLX_endStack@{XLX\_\-endStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-endStack]{\setlength{\rightskip}{0pt plus 5cm}void XLX\_\-end\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a1}


Free the memory allocated to the stack. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to free\end{description}
\end{Desc}
\hypertarget{stack_8c_a0}{
\index{stack.c@{stack.c}!XLX_initStack@{XLX\_\-initStack}}
\index{XLX_initStack@{XLX\_\-initStack}!stack.c@{stack.c}}
\subsubsection[XLX\_\-initStack]{\setlength{\rightskip}{0pt plus 5cm}unsigned XLX\_\-init\-Stack (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, unsigned int {\em limit})}}
\label{stack_8c_a0}


Initialise a stack by allocating memory to hold the contents and setting limit and used. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to initialise\item[{\em limit}]Size of the stack\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the stack was successfully initialised \item[{\em -1}]If there was an error allocating memory for the stack\end{description}
\end{Desc}
\hypertarget{stack_8c_a5}{
\index{stack.c@{stack.c}!XLX_peek@{XLX\_\-peek}}
\index{XLX_peek@{XLX\_\-peek}!stack.c@{stack.c}}
\subsubsection[XLX\_\-peek]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ XLX\_\-peek (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a5}


Look at the item on the top of the stack without removing it. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to peek at\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Item on the top of the stack\end{Desc}
\hypertarget{stack_8c_a4}{
\index{stack.c@{stack.c}!XLX_pop@{XLX\_\-pop}}
\index{XLX_pop@{XLX\_\-pop}!stack.c@{stack.c}}
\subsubsection[XLX\_\-pop]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ XLX\_\-pop (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack})}}
\label{stack_8c_a4}


Remove and return the top item on the stack. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to pop item off\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Item popped off the top of the stack\end{Desc}
\hypertarget{stack_8c_a3}{
\index{stack.c@{stack.c}!XLX_push@{XLX\_\-push}}
\index{XLX_push@{XLX\_\-push}!stack.c@{stack.c}}
\subsubsection[XLX\_\-push]{\setlength{\rightskip}{0pt plus 5cm}unsigned XLX\_\-push (\hyperlink{struct__XLX__stack}{XLX\_\-stack} $\ast$ {\em stack}, void $\ast$ {\em ptr})}}
\label{stack_8c_a3}


Put a new item on the top of the stack and increment the counter, doubling the size of the stack if the stack is already full. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stack}]Stack to push {\em ptr\/} onto\item[{\em ptr}]Pointer to push onto stack\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]If the item is added successfully \item[{\em -1}]If the stack needs to be extended to accomodate the new item and the memory allocation failed\end{description}
\end{Desc}
