-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
73 lines (56 loc) · 1.21 KB
/
stack.c
File metadata and controls
73 lines (56 loc) · 1.21 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
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "stack.h"
void Stack_Push(Stack **head, int id, void *data)
{
Stack *new_item = malloc(sizeof(Stack));
assert(new_item != NULL);
new_item->id = id;
new_item->data = data;
new_item->next = *head;
*head = new_item;
}
Stack *Stack_Pop(Stack **head)
{
Stack *top;
if(*head == NULL)
return NULL;
top = *head;
*head = top->next;
return top;
}
// This is just a reminder...
Stack *Stack_Read(Stack *head)
{
return head;
}
int Stack_Size(Stack *head)
{
Stack *sp;
int size = 0;
for(sp = head; sp != NULL; sp = sp->next)
size++;
return size;
}
/*
int main(int argc, char *argv[])
{
Stack *zoom_stack = NULL;
Stack *tmp;
Stack_Push(&zoom_stack, 1, NULL);
Stack_Push(&zoom_stack, 2, NULL);
Stack_Push(&zoom_stack, 3, NULL);
int stack_size = Stack_Size(zoom_stack);
while(zoom_stack != NULL)
{
tmp = Stack_Pop(&zoom_stack);
printf("id:%d\n", tmp->id);
}
for(tmp = zoom_stack; zoom_stack != NULL; tmp = Stack_Pop(&zoom_stack)) {
printf("id:%d\n", tmp->id);
}
Stack_Pop(&zoom_stack);
}
// Simple testcase
*/