-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonty_ops#4.c
48 lines (39 loc) · 956 Bytes
/
monty_ops#4.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
#include "monty.h"
/**
* op_rotl - subtracts the top two elements of the stack
* @dlinkedlist: pointer to list
* @line_num: line number for error
*/
void op_rotl(stack_t **dlinkedlist, unsigned int line_num)
{
stack_t *tmp = *dlinkedlist;
(void) line_num;
if (*dlinkedlist == NULL)
return;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = *dlinkedlist;
(*dlinkedlist)->prev = tmp;
tmp = (*dlinkedlist)->next;
(*dlinkedlist)->next = NULL;
*dlinkedlist = tmp;
(*dlinkedlist)->prev = NULL;
}
/**
* op_rotr - subtracts the top two elements of the stack
* @dlinkedlist: pointer to list
* @line_num: line number for error
*/
void op_rotr(stack_t **dlinkedlist, unsigned int line_num)
{
stack_t *tmp = *dlinkedlist;
(void) line_num;
if (tmp == NULL || tmp->next == NULL)
return;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->prev->next = NULL;
tmp->prev = NULL;
tmp->next = (*dlinkedlist);
*dlinkedlist = tmp;
}