-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushswap.h
370 lines (324 loc) · 10 KB
/
pushswap.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pushswap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rileone <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/10 17:59:35 by rileone #+# #+# */
/* Updated: 2024/05/04 13:11:28 by rileone ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PUSHSWAP_H
# define PUSHSWAP_H
# include "./libft/printf/ft_printf.h"
# include "./libft/libft.h"
# include "limits.h"
# include <stddef.h>
# include <stdio.h>
# include <stdlib.h>
# define LIS_INPUT_LIMIT 6
typedef struct s_stacks
{
t_dll_list *a;
t_dll_list *b;
t_dll_list *lis;
t_dll_list *o_non_lis;
t_dll_list *mosse_a;
t_dll_list *mosse_b;
int pivotindex;
int *minmax;
int minmax_len;
int *mosse;
int mosse_len;
int lis_len;
int *input_arr;
int input_arr_len;
int o_non_lis_len;
} t_stacks;
/**
* @brief Frees the memory allocated for the minisolver heap.
*
* @param stacks The pointer to the stacks structure.
*
* @return void
*/
void free_minisolver_heap(t_stacks *stacks);
/**
* Rotates the stack until it is ordered in ascending order.
*
* @param stack A pointer to the stack structure.
*/
void ft_rotate_until_ordered(t_stacks *stack);
/**
* check if the doubly linked list is ordered
* @param stacks The pointer to the stacks structure.
* @return int 1 if the list is ordered, 0 otherwise.
*/
int ft_dll_check_if_ordered(t_dll_list *stack);
/**
* @brief Performs the "rapa" operation on the given stacks.
*
* This function executes the "rapa" operation on the stacks,
* which is a custom operation specific to the program.
* The exact behavior of the "rapa" operation is not specified here.
*
* @param stacks A pointer to the `t_stacks` structure representing the stacks.
*
* @return void
*/
void rapa(t_stacks *stacks);
/**
* it s a set of moves, ra -> pa -> ra
*
* @param stacks The pointer to the stacks structure.
*/
void rapara(t_stacks *stacks);
/**
* @brief Performs a mini solver for the given stacks.
*
* This function is responsible for solving a subset
* of the problem for the given stacks.
*
* @param stacks The pointer to the stacks structure.
*
* @return void
*/
void minisolver2(t_dll_list *stacks, char x);
/**
* @brief Performs a mini solver for the given stacks.
*
* This function is responsible for solving a
* subset of the problem for the given stacks.
*
* @param stacks The pointer to the stacks structure.
*
* @return void
*/
void minisolver3(t_stacks *stacks);
/**
* @brief Solves a specific case of the problem using a mini solver.
*
* This function is responsible for solving a specific case
* of the problem using a mini solver.
* It takes a pointer to a `t_stacks` structure as a parameter.
*
* @param stacks A pointer to a `t_stacks` structure representing the stacks.
*
* @return void
*/
void minisolver4(t_stacks *stacks);
/**
* Solves a specific case of the pushswap algorithm using a mini solver.
*
* @param stacks The pointer to the stacks structure.
*/
void minisolver5(t_stacks *stacks);
/**
* @brief Free the memory allocated for the stacks structure.
* @param stack The stacks structure to be freed.
*/
void ft_free_stacks(t_stacks *stack);
/**
* @brief Normalize the input data by converting it to an array of integers.
* @param ac The number of arguments.
* @param av The array of arguments.
* @return int* The normalized array of integers.
*/
int *ft_normalizzazione_dati(int ac, char **av);
/**
* @brief Manage multiple input arguments and
* convert them to an array of integers.
* @param av The array of arguments.
* @return int* The array of integers.
*/
int *ft_manage_multiple_input(char **av);
/**
* @brief Manage string input and convert it to an array of integers.
* @param av The array of arguments.
* @return int* The array of integers.
*/
int *ft_manage_string_input(char **av);
/**
* @brief Convert a matrix of strings to an array of integers.
* @param mtx The matrix of strings.
* @return int* The array of integers.
*/
int *ft_cmtx_to_arri_coverter(char **mtx);
/**
* @brief Insert valid input arguments into an array of integers.
* @param av The array of arguments.
* @param len The length of the array.
* @param i The index of the current argument.
* @return int* The array of integers.
*/
int *ft_insertion_valid_input(char **av, int len, int i);
/**
* @brief Get the length of the input arguments.
* @param ac The number of arguments.
* @param av The array of arguments.
* @return int The length of the input.
*/
int ft_get_input_length(int ac, char **av);
/**
* @brief Initialize the stacks and input data.
* @param ac The number of arguments.
* @param av The array of arguments.
* @param stacks The stacks structure.
*/
void ft_init_(int ac, char **av, t_stacks *stacks);
/**
* @brief Sort the non-LIS (Longest Increasing Subsequence) part of the stack.
* @param stacks The stacks structure.
*/
int ft_generate_non_lis(t_stacks *stacks);
/**
* @brief Move the non-LIS (Longest Increasing Subsequence) part of the stack.
* @param stacks The stacks structure.
*/
void ft_move_non_lis(t_stacks *stacks);
/**
* @brief Sort the stack back to its original order.
* @param stack The stacks structure.
*/
void ft_sortback(t_stacks *stack);
/**
* @brief Calculate the moves for stack B.
* @param stack The stacks structure.
* @return t_dll_list* The list of moves for stack B.
*/
t_dll_list *ft_dll_calcola_mosse_b(t_stacks *stack);
/**
* @brief Calculate the moves for stack A.
* @param stack The stacks structure.
* @return t_dll_list* The list of moves for stack A.
*/
t_dll_list *ft_dll_calcola_mosse_a(t_stacks *stack);
/**
* @brief Insert a move node into the list of moves for stack A.
* @param mosse_a The list of moves for stack A.
* @param val The value of the move.
*/
int ft_insert_mosse_node(t_dll_list **mosse_a, int val);
/**
* @brief Handle the move condition "o" for the list of moves.
* @param mosse_a The list of moves for stack A.
* @param ptr_a The current node of stack A.
* @param ptr_b The current node of stack B.
* @param stack The stacks structure.
* @return int The number of moves to execute.
*/
int ft_handle_mosse_condition_o(t_dll_list **mosse_a,
t_dll_list *ptr_a,
t_dll_list *ptr_b,
t_stacks *stack);
/**
* @brief Handle the move condition "u" for the list of moves.
* @param mosse_a The list of moves for stack A.
* @param ptr_a The current node of stack A.
* @param ptr_b The current node of stack B.
* @param stack The stacks structure.
* @return int The number of moves to execute.
*/
int ft_handle_mosse_condition_u(t_dll_list **mosse_a,
t_dll_list *ptr_a,
t_dll_list *ptr_b,
t_stacks *stack);
/**
* @brief Check and insert the moves into the list of moves.
* @param mosse_a The list of moves for stack A.
* @param ptr_a The current node of stack A.
* @param ptr_b The current node of stack B.
* @param stack The stacks structure.
* @return int The number of moves to execute.
*/
int ft_check_and_insert_mosse(t_dll_list **mosse_a,
t_dll_list *ptr_a,
t_dll_list *ptr_b,
t_stacks *stack);
/**
* @brief Handle the case when stack B is empty.
* @param ptr_b The current node of stack B.
* @return t_dll_list* The updated node of stack B.
*/
t_dll_list *ft_handle_empty_stack_b(t_dll_list *ptr_b);
/**
* @brief Calculate the best move between the moves in Mova and Movb.
* @param a The list of moves for stack A.
* @param b The list of moves for stack B.
* @return int The number of moves to execute.
*/
int ft_dll_calcola_mosse(t_dll_list *a, t_dll_list *b);
/**
* @brief Check if the array is ordered.
* @param arr The array to check.
* @param len The length of the array.
* @return int 1 if the array is ordered, 0 otherwise.
*/
int check_if_ordered(int *arr, int len);
/**
* @brief Execute the moves.
* @param stack The stacks structure.
*/
void ft_execute_mosse(t_stacks *stack);
/**
* @brief Swap the top two elements of stack A.
* @param stack_a The stack A.
*/
void sa(t_dll_list *stack_a, int flag);
/**
* @brief Swap the top two elements of stack B.
* @param stack_b The stack B.
*/
void sb(t_dll_list *stack_b, int flag);
/**
* @brief Swap the top two elements of both stack A and stack B.
* @param stack_a The stack A.
* @param stack_b The stack B.
*/
void ss(t_dll_list *stack_a, t_dll_list *stack_b);
/**
* @brief Push the top element of stack B to stack A.
* @param stack_a The stack A.
* @param stack_b The stack B.
*/
void pa(t_dll_list **stack_a, t_dll_list **stack_b, int flag);
/**
* @brief Push the top element of stack A to stack B.
* @param stack_b The stack B.
* @param stack_a The stack A.
*/
void pb(t_dll_list **stack_b, t_dll_list **stack_a, int flag);
/**
* @brief Rotate the stack A.
* @param stack The stack A.
*/
void ra(t_dll_list **stack, int flag);
/**
* @brief Rotate the stack B.
* @param stack The stack B.
*/
void rb(t_dll_list **stack, int flag);
/**
* @brief Rotate both stack A and stack B.
* @param stack_a The stack A.
* @param stack_b The stack B.
*/
void rr(t_dll_list **stack_a, t_dll_list **stack_b, int flag);
/**
* @brief Reverse rotate the stack A.
* @param stack The stack A.
*/
void rra(t_dll_list **stack, int flag);
/**
* @brief Reverse rotate the stack B.
* @param stack The stack B.
*/
void rrb(t_dll_list **stack, int flag);
/**
* @brief Reverse rotate both stack A and stack B.
* @param stack_a The stack A.
* @param stack_b The stack B.
*/
void rrr(t_dll_list **stack_a, t_dll_list **stack_b, int flag);
#endif