-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstack.c
More file actions
58 lines (47 loc) · 961 Bytes
/
Copy pathstack.c
File metadata and controls
58 lines (47 loc) · 961 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
/*
* html - a simple html parser lacking a better name
* The contents of this file is licensed under the MIT License,
* see the file COPYING or http://opensource.org/licenses/MIT
*/
#include <stdlib.h>
#include "stack.h"
void *stack_push(Stack **stack, void *item) {
struct Stack *n;
if(!stack)
return NULL;
if(!(n = malloc(sizeof(Stack))))
return NULL;
n->item = item;
n->next = *stack;
*stack = n;
return item;
}
void *stack_pop(Stack **stack) {
struct Stack *p;
void *item;
if(!stack)
return NULL;
if(!(p = *stack))
return NULL;
*stack = p->next;
item = p->item;
free(p);
return item;
}
void *stack_peek(Stack **stack) {
if(!stack)
return NULL;
if(!*stack)
return NULL;
return (*stack)->item;
}
int stack_find(struct Stack **stack, int (func)(void *, void *), void *data) {
struct Stack *s;
if(!stack)
return 0;
for(s = *stack; s; s = s->next) {
if(func(s->item, data))
return 1;
}
return 0;
}