Files
42_INT_06_pushwap/srcs/pushswap.c
2021-06-12 02:20:56 +02:00

41 lines
715 B
C

#include "pushswap.h"
void is_valid(int ac, char **av)
{
if (ac < 2)
ps_stop(NULL, NULL, NULL, 1);
(void)av;
// check more error
}
t_stack *init_stack(int ac, char **av)
{
t_stack *start;
t_stack *tmp;
tmp = NULL;
while (--ac)
{
if (!(start = ft_calloc(1, sizeof(t_stack))))
ps_stop(start, NULL, NULL, 2);
start->n = ft_atoi(av[ac]);
start->next = tmp;
tmp = start;
}
return (start);
}
int main(int ac, char **av)
{
t_stack *stack;
t_list *result;
is_valid(ac, av); // check if usage and list are correct
stack = init_stack(ac, av); // create the list from av[]
result = sort_algo(stack);
ft_printf("\n%s\n", result->content);
ps_stop(stack, NULL, result, 0);
return(0);
}