-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
51 lines (35 loc) · 793 Bytes
/
stack.c
File metadata and controls
51 lines (35 loc) · 793 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
#include <stdio.h>
#include <stdlib.h>
#include "node.h"
#include "stack.h"
struct node {
int item;
node* next;
};
struct stack {
int nodes_number;
node *head;
};
stack* create_empty_stack() {
stack *new_stack = (stack*)malloc(sizeof(stack));
new_stack->nodes_number = 0;
new_stack->head = NULL;
return new_stack;
}
void push(stack *stack, int item) {
node *new_node = create_node(item);
new_node->next = stack->head;
stack->head = new_node;
stack->nodes_number++;
}
void print_stack(stack *stack) {
node *current = stack->head;
while (current != NULL) {
printf("%d ", current->item);
current = current->next;
}
putchar('\n');
}
int empty_stack(stack *stack) {
return (stack->head == NULL);
}