-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.c
103 lines (90 loc) · 1.75 KB
/
structure.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "monty.h"
/**
* push - pushes an element to the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void push(stack_t **stack, unsigned int line_number, char *data_arg)
{
stack_t *new;
int n = convertToInt(data_arg, line_number, "push");
new = malloc(sizeof(stack_t));
if (new == NULL)
{
fprintf(stderr, "Error: malloc failed\n");
exit_failure(global);
}
new->n = n;
new->prev = NULL;
if (*stack != NULL)
{
new->next = *stack;
(*stack)->prev = new;
}
else
{
new->next = NULL;
}
*stack = new;
}
/**
* enqueue - pushes an element to the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void enqueue(stack_t **stack, unsigned int line_number, char *data_arg)
{
stack_t *new;
stack_t *rear = *stack;
int n = convertToInt(data_arg, line_number, "push");
new = malloc(sizeof(stack_t));
if (new == NULL)
{
fprintf(stderr, "Error: malloc failed\n");
exit_failure(global);
}
new->n = n;
new->next = NULL;
while (rear != NULL && rear->next != NULL)
{
rear = rear->next;
}
if (rear == NULL)
{
new->prev = NULL;
*stack = new;
}
else
{
new->prev = rear;
rear->next = new;
}
}
/**
* exec_stack - pushes an element to the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_stack(stack_t **stack, unsigned int line_number, char *data_arg)
{
(void)stack;
(void)line_number;
(void)data_arg;
global->mode = 1;
}
/**
* exec_queue - pushes an element to the stack.
* @stack: pointer to stack
* @line_number: line number
* @data_arg: data arg
*/
void exec_queue(stack_t **stack, unsigned int line_number, char *data_arg)
{
(void)stack;
(void)line_number;
(void)data_arg;
global->mode = 0;
}