-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap.h
143 lines (119 loc) · 3.92 KB
/
push_swap.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yrhiba <yrhiba@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/09 10:37:29 by yrhiba #+# #+# */
/* Updated: 2023/01/24 02:19:52 by yrhiba ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PUSH_SWAP_H
# define PUSH_SWAP_H
# include "libft.h"
# include "my_list.h"
# include <fcntl.h>
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
# define DECORDER 0
# define INCORDER 1
# define SA "sa\n"
# define SB "sb\n"
# define SS "ss\n"
# define PA "pa\n"
# define PB "pb\n"
# define RA "ra\n"
# define RB "rb\n"
# define RR "rr\n"
# define RRA "rra\n"
# define RRB "rrb\n"
# define RRR "rrr\n"
typedef struct s_push_swap
{
t_my_list *stack_a;
long long size_a;
t_my_list *stack_b;
long long size_b;
int max;
int min;
} t_push_swap;
typedef struct s_data
{
int data;
int in_sub;
int cur_pos;
int tar_pos;
int cost_pa;
int cost_pb;
int cost_tp;
int lis;
int to_up;
struct s_data *prev;
} t_data;
// algorithms
void longest_incresing_sub(t_push_swap *stacks);
// parse functions
int staks_init(t_push_swap **staks);
int check_argv(int ac, char **av, t_push_swap *stacks);
// utils functions
int is_sorted(t_my_list *it, int order);
int min_int(int a, int b);
int max_int(int a, int b);
int word_count(char **strs);
int av_isvalid(char *av);
// data utils
t_data *data_dup(int data, int cur_pos);
void data_lis_init(t_push_swap *stacks);
void data_in_sub_init(t_push_swap *stacks);
// set functions
void set_tar_pos(t_push_swap *staks);
void set_prev_data(t_push_swap *stacks);
void set_lis(t_push_swap *stacks);
void set_in_sub(t_push_swap *stacks, int lis);
void set_cur_pos(t_push_swap *stacks);
// get functions
t_data *get_min_cost_pb_in_sub(t_push_swap *stacks);
int get_max_lsi(t_my_list *it);
t_data *get_max_data(t_my_list *stack);
t_data *get_min_data(t_my_list *stack);
t_data *get_to_data(t_push_swap *stacks, t_data *data);
t_data *get_min_cost_pa(t_push_swap *stacks);
// calc functions
void calc_cost_pa(t_push_swap *stacks);
void calc_cost_pb(t_push_swap *stacks);
void calc_cost_tp(t_push_swap *stacks);
int calc_size_not_in_sub(t_my_list *stack);
// operations utils functions
int swap(t_my_list **stack);
int push(t_my_list **to, t_my_list **from);
int rotate(t_my_list **stack);
int reverse_rotate(t_my_list **stack);
// operations functions
void sa(t_push_swap *stacks);
void sb(t_push_swap *stacks);
void ss(t_push_swap *stacks);
void pa(t_push_swap *stacks);
void pb(t_push_swap *stacks);
void ra(t_push_swap *stacks);
void rb(t_push_swap *stacks);
void rr(t_push_swap *stacks);
void rra(t_push_swap *stacks);
void rrb(t_push_swap *stacks);
void rrr(t_push_swap *stacks);
// sort floors utils
void rotate_m3_con(t_push_swap *stacks, t_data *to);
// sort floors
void init_floor(t_push_swap *stacks);
void floor_one(t_push_swap *stacks);
void floor_two(t_push_swap *stacks);
void end_floor(t_push_swap *stacks);
// debug functions
void print_ab(t_push_swap *staks);
void print_lsi(t_push_swap *stacks);
void print_statu(t_push_swap *stacks);
// clear functions
void ps_clear(t_push_swap *staks);
void av_clear(char **strs);
#endif