-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.c
68 lines (61 loc) · 1.91 KB
/
operations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oel-ouar <oel-ouar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 15:54:18 by oel-ouar #+# #+# */
/* Updated: 2021/11/01 18:53:12 by oel-ouar ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
void swap(t_stack **stack)
{
int tmp;
if (!(*stack) && !(*stack)->next)
return ;
else
{
tmp = (*stack)->value;
(*stack)->value = (*stack)->next->value;
(*stack)->next->value = tmp;
}
return ;
}
void rotate(t_stack **stack, int pos)
{
t_stack *cur;
t_stack *posNode;
int count;
count = 1;
cur = *stack;
if (pos == 0 || !(*stack)->next)
return ;
while (count < pos && cur != NULL)
{
cur = cur->next;
count++;
}
if (cur == NULL)
return ;
posNode = cur;
while (cur->next != NULL)
cur = cur->next;
cur->next = *stack;
*stack = posNode->next;
posNode->next = NULL;
}
void push(t_stack **stack_from, t_stack **stack_to)
{
t_stack *tmp;
if (!(*stack_from))
return ;
tmp = malloc(sizeof(t_stack));
tmp->value = (*stack_from)->value;
tmp->next = *stack_to;
*stack_to = tmp;
free(*stack_from);
*stack_from = (*stack_from)->next;
return ;
}