-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_sort.c
87 lines (80 loc) · 1.97 KB
/
util_sort.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* util_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yongmkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/19 14:26:34 by yongmkim #+# #+# */
/* Updated: 2022/03/21 01:52:14 by yongmkim ### ########seoul.kr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int fn_push_size(t_stack *stack, size_t size)
{
while (size--)
pa(stack, stack->show, NULLL);
return (0);
}
int fn_r_rotate_size(t_stack *stack, size_t size, int key)
{
if (key & A)
{
while (size--)
rra(stack, stack->show);
}
if (key & B)
{
while (size--)
{
rrb(stack, stack->show);
}
}
return (0);
}
int fn_issort_dlist_asc(t_dlist **head, size_t size)
{
t_dlist *pos;
t_dlist *mov;
size_t pos_cnt;
size_t mov_cnt;
pos = *head;
pos_cnt = 0;
while (pos && pos_cnt < size)
{
mov_cnt = 0;
mov = pos->next;
while (mov && mov_cnt++ < size)
{
if (pos->value > mov->value)
return (ERROR);
mov = mov->next;
}
pos_cnt++;
pos = pos->next;
}
return (SUCCESS);
}
int fn_issort_dlist_dsc(t_dlist **head, size_t size)
{
t_dlist *pos;
t_dlist *mov;
size_t pos_cnt;
size_t mov_cnt;
pos = *head;
pos_cnt = 0;
while (pos && pos_cnt < size)
{
mov_cnt = 0;
mov = pos->next;
while (mov && mov_cnt++ < size)
{
if (pos->value < mov->value)
return (ERROR);
mov = mov->next;
}
pos_cnt++;
pos = pos->next;
}
return (SUCCESS);
}