-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack.c
More file actions
63 lines (46 loc) · 823 Bytes
/
Copy pathStack.c
File metadata and controls
63 lines (46 loc) · 823 Bytes
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
/*
* Stack.c
*
* Created on: 2015Äê3ÔÂ29ÈÕ
* Author: lorne
*
*/
#include "Stack.h"
int len = 0;
void init_stack(stacklist *s){
*s = NULL;
}
int push_stack(stacklist *s,int item){
radomnode *node = (radomnode*)malloc(sizeof(radomnode));
node->data = item;
node->next = *s;
*s = node;
len++;
return 1;
}
int is_empty(stacklist s){
radomnode *node;
node = s;
if(!node->next) return 1;
else return 0;
}
int pop_stack(stacklist *s,int *item){
radomnode *node;
node = *s;
if(node == NULL) printf("pop err,this is a null stack\n");
*s = (*s)->next;
free(node);
node = NULL;
len--;
return 1;
}
int size_stack(){
return len;
}
int get_top_stack(stacklist s,int *item){
if(is_empty(s)) printf("this is a null stack\n");
radomnode *node;
node = s;
*item = node->data;
return 1;
}