[109] | 1 | /**
|
---|
| 2 | * @file cf_stack.c
|
---|
| 3 | * @author myusgun <myusgun@gmail.com>
|
---|
| 4 | */
|
---|
| 5 | #include "cf_stack.h"
|
---|
| 6 | #include "cf_list.h"
|
---|
| 7 | #include "cf_error.h"
|
---|
| 8 |
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 |
|
---|
| 11 | int
|
---|
| 12 | CF_Stack_CreateCtx (CF_Stack_Ctx * ctx)
|
---|
| 13 | {
|
---|
| 14 | return CF_List_CreateCtx ((CF_List_Ctx *) ctx);
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | int
|
---|
| 18 | CF_Stack_DestroyCtx (CF_Stack_Ctx ctx)
|
---|
| 19 | {
|
---|
| 20 | return CF_List_DestroyCtx (ctx);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | int
|
---|
| 24 | CF_Stack_Push (CF_Stack_Ctx ctx,
|
---|
| 25 | const void * element)
|
---|
| 26 | {
|
---|
| 27 | int result = 0;
|
---|
| 28 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 29 | CF_Traverser traverser = NULL;
|
---|
| 30 |
|
---|
| 31 | result = CF_List_Front (list, &traverser);
|
---|
| 32 | if (result < 0)
|
---|
| 33 | return result;
|
---|
| 34 |
|
---|
| 35 | return CF_List_Insert (list, traverser, CF_DIRECTION_BEFORE, element);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | int
|
---|
| 39 | CF_Stack_Pop (CF_Stack_Ctx ctx,
|
---|
| 40 | void ** element)
|
---|
| 41 | {
|
---|
| 42 | int result = 0;
|
---|
| 43 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 44 | CF_Traverser traverser = NULL;
|
---|
| 45 |
|
---|
| 46 | result = CF_Stack_Top (ctx, element);
|
---|
| 47 | if (result < 0)
|
---|
| 48 | return result;
|
---|
| 49 |
|
---|
| 50 | result = CF_List_Front (list, &traverser);
|
---|
| 51 | if (result < 0)
|
---|
| 52 | return result;
|
---|
| 53 |
|
---|
| 54 | return CF_List_Remove (ctx, &traverser);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | int
|
---|
| 58 | CF_Stack_Top (CF_Stack_Ctx ctx,
|
---|
| 59 | void ** element)
|
---|
| 60 | {
|
---|
| 61 | int result = 0;
|
---|
| 62 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 63 | CF_Traverser traverser = NULL;
|
---|
| 64 |
|
---|
| 65 | result = CF_List_Front (list, &traverser);
|
---|
| 66 | if (result < 0)
|
---|
| 67 | return result;
|
---|
| 68 |
|
---|
| 69 | return CF_List_GetElement (traverser, element);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | int
|
---|
| 73 | CF_Stack_GetSize (CF_Stack_Ctx ctx)
|
---|
| 74 | {
|
---|
| 75 | return CF_List_GetSize ((CF_List_Ctx) ctx);
|
---|
| 76 | }
|
---|