-
Notifications
You must be signed in to change notification settings - Fork 2
/
rot.c
57 lines (51 loc) · 948 Bytes
/
rot.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
#include "monty.h"
/**
* f_rotl- rotate stack element to the top
* @head: first node of stack
* @counter: line counter
*
* Return: none
*/
void f_rotl(stack_t **head, __attribute__((unused)) unsigned int counter)
{
stack_t *tmp = *head, *aux;
if (*head == NULL || (*head)->next == NULL)
{
return;
}
aux = (*head)->next;
aux->prev = NULL;
while (tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = *head;
(*head)->next = NULL;
(*head)->prev = tmp;
(*head) = aux;
}
/**
* f_rotr - rotate stack element to the bottom
* @head: first node of stack
* @counter: line counter
*
* Return: none
*/
void f_rotr(stack_t **head, __attribute__((unused)) unsigned int counter)
{
stack_t *copy;
copy = *head;
if (*head == NULL || (*head)->next == NULL)
{
return;
}
while (copy->next)
{
copy = copy->next;
}
copy->next = *head;
copy->prev->next = NULL;
copy->prev = NULL;
(*head)->prev = copy;
(*head) = copy;
}