-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_push_swap.c
52 lines (47 loc) · 1.2 KB
/
ft_push_swap.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
#include "ft_push_swap.h"
// 기능: 스택a 노드들의 랭킹 등록, 리턴: void
void enroll_rank(t_list *stack_a, int *sorted_node)
{
t_node *tmp;
int i;
i = 0;
while (stack_a->count > i)
{
tmp = stack_a->head->next;
while (tmp->data != sorted_node[i])
tmp = tmp->next;
tmp->rank = i + 1;
i++;
}
}
// 기능: 첫번째 a스택의 정렬(노드가 2개 또는 3개, 5개일 때), 리턴: void
void sort_first_a(t_list *stack_a, t_list *stack_b, int *sorted_node)
{
if (stack_a->count == 2)
sort_two_node_a(stack_a);
else if (stack_a->count == 3)
sort_three_node_a(stack_a);
else if (stack_a->count == 5)
sort_five_node_a(stack_a, stack_b, sorted_node);
}
int main(int argc, char **argv)
{
t_list stack_a;
t_list stack_b;
int *sorted_node;
if (argc < 3)
return (0);
init_list(&stack_a);
init_list(&stack_b);
sorted_node = (int *)malloc(sizeof(int) * (argc - 1));
while (*(++argv)) // ./a.out 이후 검사
check_input(*argv, &stack_a);
make_sorted_array(stack_a, sorted_node);
enroll_rank(&stack_a, sorted_node);
if (argc <= 4 || argc == 6)
sort_first_a(&stack_a, &stack_b, sorted_node);
else
algorithm(&stack_a, &stack_b);
free(sorted_node);
return (0);
}