-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_operations.c
More file actions
45 lines (39 loc) · 786 Bytes
/
Copy pathstack_operations.c
File metadata and controls
45 lines (39 loc) · 786 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 "monty.h"
/**
* add_to_stack - Adds a node to the stack.
* @new_node: Pointer to the new node.
* @ln: Interger representing the line number of of the opcode.
*/
void add_to_stack(stack_t **new_node, __attribute__((unused))unsigned int ln)
{
stack_t *tmp;
if (new_node == NULL || *new_node == NULL)
exit(EXIT_FAILURE);
if (head == NULL)
{
head = *new_node;
return;
}
tmp = head;
head = *new_node;
head->next = tmp;
tmp->prev = head;
}
/**
* pop - pop the item from the top of stack.
*
* @stack: stack pointer.
* @line_number: line number that called this funciton.
*/
void pop(stack_t **stack, unsigned int line_number)
{
stack_t *tmp;
if (*stack == NULL)
error(7, line_number);
else
{
tmp = *stack;
*stack = tmp->next;
free(tmp);
}
}