-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkstack.c
More file actions
executable file
·66 lines (50 loc) · 999 Bytes
/
Copy pathlinkstack.c
File metadata and controls
executable file
·66 lines (50 loc) · 999 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
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include "head.h"
LinkStack *create_empty_linkstack()
{
LinkStack *s;
s = (LinkStack *)malloc(sizeof(LinkStack));
s->top = NULL;
s->n = 0;
return s;
}
int is_empty_linkstack(LinkStack *s)
{
return s->top == NULL ? 1 : 0;
}
DATATYPE get_top_linkstack(LinkStack *s)
{
if(is_empty_linkstack(s))
{
printf("The LinkStack is empty!\n");
return -1;
}
return s->top->data;
}
int push_linkstack(LinkStack *s,DATATYPE data)
{
LinkNode *temp;
temp = (LinkNode *)malloc(sizeof(LinkNode));
temp->data = data;
temp->next = s->top;
s->top = temp;
s->n ++;
return 0;
}
DATATYPE pop_linkstack(LinkStack *s)
{
DATATYPE data;
LinkNode *temp;
if(is_empty_linkstack(s))
{
printf("The LinkStack is empty!\n");
return -1;
}
temp = s->top;
s->top = temp->next;
data = temp->data;
free(temp);
s->n --;
return data;
}