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