-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_queue_opcode.c
More file actions
87 lines (78 loc) · 1.64 KB
/
stack_queue_opcode.c
File metadata and controls
87 lines (78 loc) · 1.64 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "monty.h"
/**
* queue - set data structure of queue
* @stack: stack
* @line_number: line number or the command
*/
void queue(stack_t **stack, unsigned int line_number)
{
(void)stack;
(void)line_number;
global->status = 1;
}
/**
* stack - set data structure of stack
* @stack: stack
* @line_number: line number or the command
*/
void stack(stack_t **stack, unsigned int line_number)
{
(void)stack;
(void)line_number;
global->status = 0;
}
/**
* add_node_stack - add element at the top of the stack
* Return: new_element address
*/
stack_t *add_node_stack(void)
{
stack_t *new_element = NULL;
new_element = malloc(sizeof(stack_t));
if (new_element == NULL)
exit(error_msg(2));
new_element->n = atoi(global->arr[1]);
if (!(global->stack))
{
new_element->prev = NULL;
new_element->next = NULL;
global->stack = new_element;
}
else
{
new_element->next = global->stack;
new_element->prev = (global->stack)->prev;
(global->stack)->prev = new_element;
global->stack = new_element;
}
return (new_element);
}
/**
* add_node_queue - add element at the end of the queue
* Return: new_element address
*/
stack_t *add_node_queue(void)
{
stack_t *new_element = NULL;
stack_t *tail = NULL;
new_element = malloc(sizeof(stack_t));
if (new_element == NULL)
exit(error_msg(2));
new_element->n = atoi(global->arr[1]);
if (!(global->stack))
{
new_element->prev = NULL;
new_element->next = NULL;
global->stack = new_element;
}
else
{
tail = global->stack;
while (tail->next)
tail = tail->next;
new_element->next = tail->next;
tail->next = new_element;
new_element->prev = tail;
}
return (new_element);
}