-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub.c
35 lines (34 loc) · 762 Bytes
/
sub.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
29
30
31
32
33
34
35
#include "monty.h"
/**
* sub - subtracts the top element of the stack
* from the second top element of the stack
* @stack: pointer to new node to be pushed
* @line_number: line number of opcode in monty file
*/
void sub(stack_t **stack, unsigned int line_number)
{
(void) stack;
(void) line_number;
if (info_glob.nodes >= 2)
{
stack_t *temp;
if (info_glob.cur_type == STACK)
{
temp = info_glob.head->next;
temp->n -= info_glob.head->n;
free(temp->prev);
temp->prev = NULL;
info_glob.head = temp;
info_glob.nodes--;
}
else if (info_glob.cur_type == QUEUE)
{
temp = info_glob.tail->prev;
temp->n -= info_glob.tail->n;
free(temp->next);
temp->next = NULL;
info_glob.tail = temp;
info_glob.nodes--;
}
}
}