-
Notifications
You must be signed in to change notification settings - Fork 0
/
opfuncs2.c
94 lines (88 loc) · 1.57 KB
/
opfuncs2.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
#include "monty.h"
/**
* rotr- rotate bottom to top
* @stack: head of stack
* @linenumber: current ln
*
*/
void rotr(stack_t **stack, __attribute__((unused))unsigned int linenumber)
{
stack_t *first, *second;
if (!(*stack) || !(*stack)->next)
{
return;
}
first = *stack;
while (first->next->next)
{
first = first->next;
}
second = first->next;
first->next = NULL;
(*stack)->prev = second;
second->next = *stack;
second->prev = NULL;
*stack = second;
}
/**
* stack_op - makes it stack format (default)
* @stack: head of stack
* @linenumber: current ln
*
*/
void stack_op(stack_t **stack, unsigned int linenumber)
{
(void)stack;
(void)linenumber;
monty.is_queue = false;
}
/**
* queue_op - makes it queue format
* @stack: head of stack
* @linenumber: current ln
*/
void queue_op(stack_t **stack, unsigned int linenumber)
{
(void)stack;
(void)linenumber;
monty.is_queue = true;
}
/**
* push_queue - add node to end list
* @argument: int
*/
void push_queue(char *argument)
{
int data;
stack_t *new, *location;
if (!check_input(argument))
{
dprintf(STDERR_FILENO, "L%u: usage: push integer\n",
monty.line_number);
free_it_all();
exit(EXIT_FAILURE);
}
data = atoi(argument);
new = malloc(sizeof(stack_t));
if (!new)
{
dprintf(STDERR_FILENO, "Error: malloc failed\n");
free_it_all();
exit(EXIT_FAILURE);
}
location = monty.stack;
new->n = data;
new->next = NULL;
if (!location)
{
new->prev = NULL;
monty.stack = new;
return;
}
while (location->next)
{
location = location->next;
}
location->next = new;
new->prev = location;
}