-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_func3.c
77 lines (61 loc) · 1.46 KB
/
stack_func3.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
#include "monty.h"
/**
* _pstr - mod top of stack y second top stack
* @stack: pointer to lists for monty stack
* @line_number: number of line opcode occurs on
*/
void _pstr(stack_t **stack, unsigned int line_number)
{
stack_t *tmp = *stack;
int c = 0;
(void)line_number;
while (tmp)
{
c = tmp->n;
if (c == 0 || _isalpha(c) == 0)
break;
putchar(c);
tmp = tmp->next;
}
putchar('\n');
}
/**
* _rotl - mod top of stack y second top stack
* @stack: pointer to lists for monty stack
* @line_number: number of line opcode occurs on
*/
void _rotl(stack_t **stack, unsigned int line_number)
{
stack_t *runner = *stack;
int aux1 = 0;
if (!line_number || !stack || !*stack || !(*stack)->next)
return;
aux1 = runner->n;
while (runner->next)
{
runner = runner->next;
runner->prev->n = runner->n;
}
runner->n = aux1;
}
/**
* _rotr - mod top of stack y second top stacks
* @stack: pointer to lists for monty stack
* @line_number: number of line opcode occurs on
*/
void _rotr(stack_t **stack, unsigned int line_number)
{
stack_t *runner = *stack;
int aux1 = 0;
if (!line_number || !stack || !*stack || !(*stack)->next)
return;
while (runner->next)
runner = runner->next;
aux1 = runner->n;
while (runner->prev)
{
runner = runner->prev;
runner->next->n = runner->n;
}
runner->n = aux1;
}