-
Notifications
You must be signed in to change notification settings - Fork 31
/
stack.c
68 lines (55 loc) · 1.2 KB
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* _____
* ANSI / ___/
* / /__
* \___/
*
* Filename: stack.c
* Author : Kyle Loudon/Dan Levin
* Date : Fri Mar 22 12:40:45 GMT 2013
* Version : 0.51
* ---
* Description: An implementation of a generic, stack ADT.
*
* Date Revision message
* 2012-12-20 Created this file
* 2013-02-19 Made some revision to the Doxygen documentation. Enhanced the description of
* in/out parameters - i.e. double-pointers.
* 2015-03-31 This code ready for version 0.51
*/
/**
* @file stack.c
*
**/
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
/* FUNCTION DEFINITIONS --------------------------------------------------- */
Stack STACKinit(void (*destroy)(void *data))
{
return SLISTinit(destroy);
}
void STACKdestroy(Stack stk)
{
SLISTdestroy(stk);
}
int STACKpush(Stack stk, const void *data)
{
return SLISTinsnext(stk, NULL, data);
}
int STACKpop(Stack stk, void **data)
{
return SLISTremnext(stk, NULL, data);
}
void *STACKpeek(Stack stk)
{
return SLISTsize(stk) == 0 ? NULL : SLISTdata(SLISThead(stk));
}
int STACKisempty(Stack stk)
{
return SLISTsize(stk) == 0 ? 1 : 0;
}
int STACKsize(Stack stk)
{
return SLISTsize(stk);
}