-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_check.c
78 lines (69 loc) · 1.84 KB
/
stack_check.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhuthmay <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 13:01:16 by mhuthmay #+# #+# */
/* Updated: 2024/11/05 13:34:24 by mhuthmay ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int is_sorted(t_stack *stack)
{
t_node *current;
if (!stack || !stack->head)
return (1);
current = stack->head;
while (current->next)
{
if (current->value > current->next->value)
return (0);
current = current->next;
}
return (1);
}
int get_min(t_stack *stack)
{
t_node *current;
int min;
if (!stack || !stack->head)
return (0);
current = stack->head;
min = current->value;
while (current)
{
if (current->value < min)
min = current->value;
current = current->next;
}
return (min);
}
int get_max(t_stack *stack)
{
t_node *current;
int max;
if (!stack || !stack->head)
return (0);
current = stack->head;
max = current->value;
while (current)
{
if (current->value > max)
max = current->value;
current = current->next;
}
return (max);
}
t_node *new_node(int value)
{
t_node *new;
new = malloc(sizeof(t_node));
if (!new)
return (NULL);
new->value = value;
new->next = NULL;
new->prev = NULL;
return (new);
}