-
Notifications
You must be signed in to change notification settings - Fork 0
/
2ft_stack.c
executable file
·63 lines (56 loc) · 1.56 KB
/
2ft_stack.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 2ft_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: skarunat <skarunat@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/30 11:27:46 by skarunat #+# #+# */
/* Updated: 2023/08/05 18:52:22 by skarunat ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static t_stack *ft_get_next_min(t_stack **stack)
{
t_stack *head;
t_stack *min;
int min_num;
min = NULL;
min_num = 0;
head = *stack;
if (head)
{
while (head)
{
if ((head->index == -1) && (!min_num || head->value < min->value))
{
min = head;
min_num = 1;
}
head = head->next;
}
}
return (min);
}
void ft_stack_index(t_stack **stack)
{
t_stack *head;
int index;
index = 0;
head = ft_get_next_min(stack);
while (head)
{
head->index = index++;
head = ft_get_next_min(stack);
}
}
void ft_node_add_front(t_stack **stack, t_stack *new)
{
new->next = *stack;
*stack = new;
}
void ft_error(char *msg)
{
ft_putendl_fd(msg, 1);
exit(0);
}