-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
61 lines (51 loc) · 1.49 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
/***************************************************************************
stack.c - description
-------------------
begin : Wed Feb 9 14:03:54 EST 2006
copyright : (C) 2006-2010 by XVilka
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdlib.h>
#include "stack.h"
typedef struct STACKnode* link;
struct STACKnode
{
Item item;
link next;
};
static link head;
link NEW(Item item, link next)
{
link x = malloc(sizeof *x);
x->item = item;
x->next = next;
return x;
}
void STACKinit(int maxN)
{
head = NULL;
}
int STACKempty(void)
{
return head == NULL;
}
void STACKpush(Item item)
{
head = NEW(item, head);
}
Item STACKpop(void)
{
Item item = head->item;
link t = head->next;
free(head);
head = t;
return item;
}