-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop.c
28 lines (27 loc) · 646 Bytes
/
pop.c
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
#include "monty.h"
/**
* pop - perform pop operation in a stack/queue
* @stack: pointer to new node to be pushed
* @line_number: line number of opcode in monty file
*/
void pop(stack_t **stack, unsigned int line_number)
{
stack_t *current;
(void) stack;
(void) line_number;
if (info_glob.cur_type == STACK && info_glob.nodes > 0)
{
current = info_glob.head;
info_glob.head = current->next;
free(current);
info_glob.nodes--;
}
else if (info_glob.cur_type == QUEUE && info_glob.nodes > 0)
{
current = info_glob.tail;
info_glob.tail = current->prev;
info_glob.tail->next = NULL;
free(current);
info_glob.nodes--;
}
}