arraystack.h File Reference

This header file contains the structures and functions needed to work with stacks (implemented using array lists). More...


Typedefs

typedef arraystack_adt * ArrayStack
 Pointer to structure reprsenting a stack.

Functions

ArrayStack AS_New ()
 Creates a new stack.
void AS_Free (ArrayStack stack)
 Destroys the specified stack.
int AS_Size (ArrayStack stack)
 Returns the size of the stack.
int AS_Empty (ArrayStack stack)
 Determines if the stack is empty or not.
void AS_Push (ArrayStack stack, void *el)
 Adds an element to the top of the stack.
void AS_Pop (ArrayStack stack)
 Removes an element from the top of the stack.
void * AS_Top (ArrayStack stack)
 Retrieves the data in the element at the top of the stack. The function returns the data in the element at the top of the stack but does not alter in any way the structure of the stack. However the actual data can be changed through the use of the void* pointer returned, which points to the memory location containing the data.


Detailed Description

This header file contains the structures and functions needed to work with stacks (implemented using array lists).

Author:
Stefan Bucur
It contains functions for creating a stack, destroying it and all the typical operations on a stack (push, pop, top).

Typedef Documentation

typedef struct arraystack_adt* ArrayStack

Pointer to structure reprsenting a stack.

The ArrayStack is implemented using an ArrayList . However, the underlying ArrayList should not be modified directly but only through the appropriate functions.

As is the case with the ArrayList element data is stored using a void* pointer. Thus, one should note there is no way to tell what kind of data is stored in the list or in a particular element.

See also:
AS_New(), AS_Free(), AS_Pop(), AS_Push(), AS_Top()


Function Documentation

int AS_Empty ( ArrayStack  stack  ) 

Determines if the stack is empty or not.

The function actually returns the value of the expression Size==0.

Parameters:
stack the stack to be tested.
Returns:
-1 if the stack stack is NULL, 1 if the stack is empty, 0 otherwise.

void AS_Free ( ArrayStack  stack  ) 

Destroys the specified stack.

The function frees the memory used by the stack structure itself as well as the memory used by the data in the stack, so trying to access the data after the destruction of the stack (e.g. through a pointer) will most likely result in a Access violation / segfault.

Parameters:
stack ArrayStack representing the stack to be destroyed.

ArrayStack AS_New (  ) 

Creates a new stack.

The function creates a new array stack (stack implemented using an ArrayList ). Thus, the stack can grow to accomodate as many elements as needed.

Returns:
pointer to the newly created stack.

void AS_Pop ( ArrayStack  stack  ) 

Removes an element from the top of the stack.

The function removes the element at the top of the stack. Note that the data in that element is not freed, so that it can be further referenced.

Parameters:
stack the stack on which to perfom the operation
See also:
AS_Top()

void AS_Push ( ArrayStack  stack,
void *  el 
)

Adds an element to the top of the stack.

The function adds the data specified by el to the top of the stack.

Parameters:
stack the stack to add data to.
*el pointer to a initialized memory location containing the data to be added at the top of the stack.

int AS_Size ( ArrayStack  stack  ) 

Returns the size of the stack.

The function returns the number of elements in the stack.

Parameters:
stack stack to be tested.
Returns:
number of elements in stack.

void* AS_Top ( ArrayStack  stack  ) 

Retrieves the data in the element at the top of the stack. The function returns the data in the element at the top of the stack but does not alter in any way the structure of the stack. However the actual data can be changed through the use of the void* pointer returned, which points to the memory location containing the data.

Parameters:
stack the stack on which to perform the operation
Returns:
if stack is NULL or empty, it returns NULL . Otherwise, it returns a pointer to the memory location where the data in the element at the top of the stack is stored.


Generated on Sun Mar 18 17:24:46 2007 for Cobble by  doxygen 1.5.1