-
Notifications
You must be signed in to change notification settings - Fork 2
/
opcode_init4.c
63 lines (51 loc) · 1.02 KB
/
opcode_init4.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
#include "monty.h"
/**
* _rotl - rotates the first element to the bottom and the second to the top
*
* @doubly: head of the linked list
* @cline: line number;
* Return: no return
*/
void _rotl(stack_t **doubly, unsigned int cline)
{
stack_t *aux1 = NULL;
stack_t *aux2 = NULL;
(void)cline;
if (*doubly == NULL)
return;
if ((*doubly)->next == NULL)
return;
aux1 = (*doubly)->next;
aux2 = *doubly;
for (; aux2->next != NULL; aux2 = aux2->next)
;
aux1->prev = NULL;
aux2->next = *doubly;
(*doubly)->next = NULL;
(*doubly)->prev = aux2;
*doubly = aux1;
}
/**
* _rotr - reverse the stack
*
* @doubly: head of the linked list
* @cline: line number
* Return: no return
*/
void _rotr(stack_t **doubly, unsigned int cline)
{
stack_t *aux = NULL;
(void)cline;
if (*doubly == NULL)
return;
if ((*doubly)->next == NULL)
return;
aux = *doubly;
for (; aux->next != NULL; aux = aux->next)
;
aux->prev->next = NULL;
aux->next = *doubly;
aux->prev = NULL;
(*doubly)->prev = aux;
*doubly = aux;
}