-
Notifications
You must be signed in to change notification settings - Fork 1
/
implement.c
61 lines (53 loc) · 1002 Bytes
/
implement.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
#include "push_swap.h"
void push(t_push_swappa **push, t_push_swappa **take, t_push_swappa **t_push, t_push_swappa **t_take)
{
t_push_swappa *curr;
if (*push == NULL)
return ;
curr = *push;
if ((*push)->next != *push)
{
*push = (*push)->next;
(*t_push)->next = *push;
(*push)->prev = *t_push;
}
else
{
*push = NULL;
*t_push = NULL;
}
if (*take != NULL)
{
curr->next = *take;
curr->prev = (*take)->prev;
(*take)->prev->next = curr;
(*take)->prev = curr;
*take = curr;
}
else
{
curr->next = curr;
curr->prev = curr;
*t_take = curr;
*take = curr;
}
if (*t_take == NULL)
*t_take = *take;
(*t_take)->next = *take;
(*take)->prev = *t_take;
}
void rotate(t_push_swappa **head, t_push_swappa **tail, int up_down)
{
if (*head == NULL)
return ;
if (up_down == 1)
{
*tail = *head;
*head = (*head)->next;
}
else if (up_down == -1)
{
*head = *tail;
*tail = (*head)->prev;
}
}