-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
48 lines (44 loc) · 1.52 KB
/
init.c
File metadata and controls
48 lines (44 loc) · 1.52 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kikiz <kikiz@student.42istanbul.com.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/23 19:13:18 by kikiz #+# #+# */
/* Updated: 2025/04/07 17:14:15 by kikiz ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_stack *get_stack_a(int argc, char **argv,
t_stack **stack_a, t_stack **stack_b)
{
*stack_a = extract_numbers(all_args(argc, argv));
if (check_duplicate(*stack_a))
{
write(2, "Error\n", 6);
exit(1);
}
*stack_b = NULL;
return (*stack_a);
}
void index_stack(t_stack *stack_a, int stack_size)
{
t_stack *current;
t_stack *highest;
while (stack_size > 0)
{
current = stack_a;
highest = NULL;
while (current)
{
if (current->index == 0 && (highest == NULL
|| current->value > highest->value))
highest = current;
current = current->next;
}
if (highest)
highest->index = stack_size;
stack_size--;
}
}