-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.c
More file actions
43 lines (36 loc) · 670 Bytes
/
Copy pathstack.c
File metadata and controls
43 lines (36 loc) · 670 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
#include "stack.h"
#include "vector.h"
#include <stdlib.h>
struct stack_tag
{
vector_t vect;
};
stack_t stack_new(void)
{
stack_t ret = malloc(sizeof(struct stack_tag));
ret->vect = vector_new();
return ret;
}
void stack_delete(stack_t s)
{
vector_delete(s->vect);
free(s);
}
void stack_push(stack_t s, element_t el)
{
vector_push_back(s->vect, el);
}
element_t stack_pop(stack_t s)
{
element_t ret = stack_top(s);
vector_remove(s->vect);
return ret;
}
element_t stack_top(stack_t s)
{
return vector_get_element(s->vect, vector_size(s->vect) - 1);
}
bool stack_is_empty(stack_t s)
{
return !vector_size(s->vect);
}