-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.h
115 lines (99 loc) · 2.86 KB
/
stack.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
begin........: June 2012
copyright....: Sebastian Fedrau
email........: [email protected]
***************************************************************************/
/***************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v3 as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License v3 for more details.
***************************************************************************/
/**
* \file stack.h
* \brief Generic stack.
* \author Sebastian Fedrau <[email protected]>
*/
#ifndef STACK_H
#define STACK_H
#include "slist.h"
/**
*\typedef Stack
*\brief Generic stack.
*/
typedef SList Stack;
/**
*\typedef StackItem
*\brief Holds stack item data & pointer to next element.
*/
typedef SList StackItem;
/**
*\param compare function to compare item data
*\param free function to free item data or NULL
*\param pool a user-defined memory pool for creating/destroying StackItems or NULL
*\return a new Stack
*
* Creates a new Stack.
*/
#define stack_new(compare, free, pool) slist_new(compare, free, pool)
/**
*\param stack a Stack
*\param compare function to compare item data
*\param free function to free item data or NULL
*\param pool a user-defined memory pool for creating/destroying StackItems or NULL
*
* Initializes a Stack.
*/
#define stack_init(stack, compare, free, pool) slist_init(stack, compare, free, pool)
/**
*\param stack a Stack
*
* Frees all items in the stack and the stack pointer.
*/
#define stack_destroy(stack) slist_destroy(stack)
/**
*\param stack a Stack
*
* Frees all items in the stack without freeing the stack pointer.
*/
#define stack_free(stack) slist_free(stack)
/**
*\param stack a Stack
*\param data data to push
*
* Pushs data onto the stack.
*/
#define stack_push(stack, data) slist_prepend(stack, data)
/**
*\param stack a Stack
*\param data location to store data
*\return true if stack is not empty
*
* Gets first element from stack without removing it.
*/
bool stack_head(const Stack *stack, void **data);
/**
*\param stack a Stack
*\param data location to store data
*\return true if stack is not empty
*
* Pops the first element from the stack.
*/
bool stack_pop(Stack *stack, void **data);
/**
*\param stack a Stack
*
* Clears a stack.
*/
#define stack_clear(stack) slist_clear(stack)
/**
*\param stack a Stack
*\return number of items
*
* Gets the number of stored items.
*/
#define stack_count(stack) slist_count(stack)
#endif