-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstack.c
More file actions
45 lines (38 loc) · 681 Bytes
/
Copy pathstack.c
File metadata and controls
45 lines (38 loc) · 681 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
#include "stack.h"
#include<stdlib.h>
int stack_init(struct Stack* self)
{
if(self == NULL)
{
return -1;
}
self->head = NULL;
return 0;
}
int stack_empty(struct Stack* self)
{
return self->head == NULL;
}
int stack_push(struct Stack* self,void *data)
{
struct Stack_node* newnode = malloc(sizeof(struct Stack_node));
if(newnode == NULL)
return -1;
else
{
newnode->data = data;
newnode->next = self->head;
self->head = newnode;
return 0;
}
}
void* stack_pop(struct Stack* self)
{
if(self->head == NULL)
return NULL;
void* data = self->head->data;
struct Stack_node* next = self->head->next;
free(self->head);
self->head = next;
return data;
}