-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.c
78 lines (69 loc) · 1.17 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
68
69
70
71
72
73
74
75
76
77
78
/*
* =====================================================================================
*
* Filename: Stack.c
*
* Description:
*
* Version: 1.0
* Created: 11/29/2014 08:23:30 PM
* Revision: none
* Compiler: gcc
*
* Author: 张世龙 (mn), [email protected]
* Company: free
*
* =====================================================================================
*/
#include "Public.h"
#include "Stack.h"
void InitStack(SqStack *s)
{
assert(s);
s->top = -1;
}
void DestoryStack(SqStack *s)
{
assert(s);
s->top = -1;
}
void ClearStack(SqStack *s)
{
assert(s);
s->top = -1;
}
int StackEmpty(SqStack *s)
{
assert(s);
return s->top==-1;
}
int GetTop(SqStack *s,ElemType *e)
{
assert(s || e);
if(s->top == -1)
return ERROR;
*e = s->data[s->top];
return SUCCESS;
}
int Push(SqStack *s,ElemType *e)
{
assert(s || e);
if(s->top >= MAXSIZE-1)
return ERROR;
s->top++;
s->data[s->top] = *e;
return SUCCESS;
}
int Pop(SqStack *s,ElemType *e)
{
assert(s || e);
if(s->top == -1)
return ERROR;
*e = s->data[s->top--];
return SUCCESS;
}
int StackLength(SqStack *s)
{
assert(s);
return s->top+1;
}