forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLINKED_STACK.c
More file actions
46 lines (35 loc) · 692 Bytes
/
LINKED_STACK.c
File metadata and controls
46 lines (35 loc) · 692 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
#include <stdio.h>
#include <stdlib.h>
// LINKED_STACK
typedef struct node{
int info;
struct node *next;
}NODE;
typedef NODE * LINKED_STACK;
void create_stack(LINKED_STACK *p){
*p = NULL;
}
int isEmpty(LINKED_STACK p){
return (p == NULL);
}
void insert(LINKED_STACK *p, int info){
NODE *new_node;
new_node = (NODE *) malloc (sizeof(NODE));
if(!new_node){
puts("Memory FULL\n");
exit(1);
}
new_node->info = info;
new_node->next = *p;
*p = new_node;
}
void removeSTACK (LINKED_STACK *p){
NODE *aux = *p;
if(isEmpty(*p)){
puts("Stack is Empty\n");
exit(2);
}
(*p) = (*p)->next;
free(aux);
}
int main(){}