-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic-stack.h
50 lines (36 loc) · 1.15 KB
/
generic-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
/************************************************************************
*
* File name: generic-stack.h
* Description: Stack's API
* Author: dennis_fan(dennis_fan@outlook.com), 2013/2/26
* Version: 1.0
*************************************************************************/
#ifndef _STACK_H
#define _STACK_H
typedef void *ElementAddr;
typedef void (*PfCbFree)(ElementAddr);
typedef struct StackRecord
{
ElementAddr *array;
int elemsize;
int loglength;
int alloclength;
PfCbFree freefn;
} *Stack;
/* Create a new stack */
Stack stack_create(int elemsize, PfCbFree freefn);
/* Dispose the stack */
void stack_dispose(Stack stk);
/* Make the given stack empty */
void stack_make_empty(Stack stk);
/* Return true if the stack is empty */
int stack_is_empty(Stack stk);
/* Insert a new element onto stack */
void stack_push(Stack stk, ElementAddr elemaddr);
/* Delete the top element off the stack */
void stack_pop(Stack stk);
/* Fetch the top element from the stack */
void stack_top(Stack stk, ElementAddr elemaddr);
/* Fetch & Delete the top element from the stack */
void stack_top_and_pop(Stack stk, ElementAddr elemaddr);
#endif /* THE END */