forked from morgengc/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
62 lines (50 loc) · 1.2 KB
/
stack.h
File metadata and controls
62 lines (50 loc) · 1.2 KB
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
/****************************************
* Stack using Single list.
*
* 2009.09.10
***************************************/
#ifndef __STACK_H__
#define __STACK_H__
/* defined by gcc */
#include "stdbool.h"
#define ELEMENT_TYPE int
typedef struct Node{
ELEMENT_TYPE data;
struct Node *next;
}NODE;
typedef struct Stack{
struct Node *top;
}STACK;
#define CHECK_MEMORY(x) \
if ((x) == NULL) \
{ printf("[%s]:[%s()] no available memory.\n", \
__FILE__, __FUNCTION__); \
return NULL;\
}
#define CHECK_RETURN(x) \
if ((x) == NULL) \
{ printf("[%s]:[%s()] return error.\n", \
__FILE__, __FUNCTION__); \
return NULL;\
}
#define CHECK_VALID(x) \
if ((x) == NULL) \
{ printf("[%s]:[%s()] NULL, not valid.\n", \
__FILE__, __FUNCTION__); \
return NULL;\
}
#define V_CHECK_VALID(x) \
if ((x) == NULL) \
{ printf("[%s]:[%s()] NULL, not valid.\n", \
__FILE__, __FUNCTION__); \
return;\
}
STACK *CreateStack();
void DestroyStack(STACK *s);
bool GetTop(STACK *s, ELEMENT_TYPE *e);
STACK *Push(STACK *s, ELEMENT_TYPE e);
STACK *Pop(STACK *s, ELEMENT_TYPE *e);
bool IsEmpty(STACK *s);
void PrintStack(STACK *s);
#endif // __STACK_H__