Introduction | Initialization | Closing | Adding | Deleting | Fetching | Parameters | Advanced | Obscure

STACK

Yes, LibDS has a stack implementation as well. This is in keeping with the name and purpose of the library.

Introduction

A stack is a data structure that supports the last-in first-out processing of data. Data are pushed onto the stack in a particular order. To retrieve data, it is popped off the stack. The invariant here is that the order in which the items come off the stack is exactly the reverse order in which they were pushed onto the stack.

LibDS refers to a stack as STACK.

Initialization

STACK stkMake(void)

Create a new STACK. Returns NULL on failure.

Closing

void stkClose(STACK stack)

Close the stack, releasing all memory it was using. User data is left untouched.

void stkCloseWithFunction(STACK stack,void (*fun)(void*))

Close the stack and call fun on each data in the stack.

Adding

int stkPush(STACK stack,void *data)

Pushes this data onto the stack. Returns 0 on success, -1 on failure.

Deleting

void* stkPop(STACK stack)

Pops the top item from the stack and return it. Returns NULL if stack is empty.

Fetching

void* stkPeek(STACK stack)

Returns, without removing it, the top item on the stack. Returns NULL if the stack is empty.

Parameters

int stkSize(STACK stack)

Returns the number of items currently on the stack.

int stkEmpty(STACK stack)

Returns 0 if the stack still has items on it, 1 if it is empty.

Advanced functionality

What exactly did you have in mind?

Obscure functionality

None whatsoever.


Sat Dec 15 18:31:13 EST 2001