-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotl_and_rotr.c
More file actions
55 lines (48 loc) · 865 Bytes
/
Copy pathrotl_and_rotr.c
File metadata and controls
55 lines (48 loc) · 865 Bytes
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
#include "monty.h"
/**
* _rotl - rotates the stack to the top.
* @stack: pointer to a stack_t lists
* @n: line count
*
* Return: void has no return
*/
void _rotl(stack_t **stack, unsigned int n)
{
stack_t *h = NULL, *t = NULL;
(void) n;
if (!stack || !(*stack) || !(*stack)->next)
return;
h = *stack;
t = h->next;
t->prev = NULL;
*stack = t;
while (t->next)
{
t = t->next;
}
t->next = h;
h->prev = t;
h->next = NULL;
}
/**
* _rotr - rotates the stack to the bottom.
* @stack: pointer to a stack_t lists
* @n: line count
*
* Return: void has no return
*/
void _rotr(stack_t **stack, unsigned int n)
{
stack_t *h = NULL, *t = NULL;
(void) n;
if (!stack || !(*stack) || !(*stack)->next)
return;
t = h = *stack;
while (h->next)
h = h->next;
h->prev->next = NULL;
h->next = t;
h->prev = NULL;
t->prev = h;
*stack = h;
}