Description | Stack data structure |
Header file | LStack.h |
Author | Camil Demetrescu |
Created | Nov 27, 2003 |
Last updated | Nov 27, 2003 |
Constants |
|
LStack_ID LStack_EMPTY_STACK |
Types |
|
LStack |
Functions |
|
LStack* LStack_New (LType_TType inItemType); void LStack_Delete (LStack** ThisA); Bool LStack_IsEmpty (LStack* This); ui4 LStack_GetItemsCount (LStack* This); void LStack_Push (LStack* This, const void* inItem); void LStack_Pop (LStack* This); void LStack_Top (LStack* This, void* outItem); void LStack_MultiPop (LStack* This, ui4 inItemsCount); ui4 LStack_GetUsedMem (LStack* This); LType_TType LStack_GetItemType (LStack* This); |
Function | Arguments | Description | Returns | Throws |
New |
LType_TType inType |
Creates object containing an empty stack with items of type inType. Caller is responsible of dellocating the created object using LStack_Delete. |
LStack* pointer to newly created object |
- |
Delete | LStack** ThisA | Releases object *ThisA. *ThisA is set to NULL | - | - |
IsEmpty |
LStack* This | Returns TRUE if the data structure is empty, and FALSE otherwise | Bool | - |
GetItemsCount | LStack* This | Returns the number of items in the stack | ui4 | |
Push |
LStack* This void* inItem |
Puts the item pointed to by inItem on top of the stack | - |
- |
Top |
LStack* This void* outItem |
Copies the item on top of the stack to address outItem | - | LStack_EMPTY_STACK, if the stack is empty |
Pop |
LStack* This |
Removes the item on top of the stack | - | LStack_EMPTY_STACK, if the stack is empty |
MultiPop |
LStack* This |
Removes the inItemsCount topmost items from the stack. If inItemsCount is greater than the size of the stack, the stack gets empty | - | - |
GetUsedMem | LStack* This | Returns the memory usage (in bytes) of the data structure | ui4 | - |
GetBaseType | LStack* This | Returns the type descriptor of stack items | LType_TType | - |
#include "LStack.h" #include "LException.h" #include "LDebug.h" int main() { ui4 i; LStack* theStack = NULL; LException* theExcep; Try { /* create new stack */ theStack = LStack_New(LType_UI4); /* adds values to the stack */ for (i=100; i>0; --i) LStack_Push(theStack, &i); /* extracts all values from the stack */ while (!LStack_IsEmpty(theStack)) { LStack_Top(theStack, &i); LStack_Pop(theStack); LDebug_Print("Extracted value: %lu\n", i); } } Catch(theExcep) { LException_Dump(theExcep); } if (theStack != NULL) LStack_Delete(&theStack); return 0; }