-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_format.c
39 lines (37 loc) · 905 Bytes
/
set_format.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
#include "monty.h"
/**
* queue_op - changes the stack to a queue
* @stack: the stack
* @line_number: the line_number
*/
void queue_op(stack_t **stack, unsigned int line_number)
{
stack_t *current_element = *stack;
(void) line_number;
if (globals.mode == 1)
return;
globals.mode = 1;
if (*stack == NULL || (*stack)->next == NULL)
return;
while (current_element->next != NULL)
current_element = current_element->next;
*stack = current_element;
}
/**
* stack_op - changes the queue to a stack
* @stack: the stack
* @line_number: the line_number
*/
void stack_op(stack_t **stack, unsigned int line_number)
{
stack_t *current_element = *stack;
(void) line_number;
if (globals.mode == 0)
return;
globals.mode = 0;
if (*stack == NULL || (*stack)->prev == NULL)
return;
while (current_element->prev != NULL)
current_element = current_element->prev;
*stack = current_element;
}