Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
67
sources/main.c
Executable file
67
sources/main.c
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/13 23:58:38 by jotavare #+# #+# */
|
||||
/* Updated: 2024/04/18 15:18:22 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/push_swap.h"
|
||||
|
||||
static void init_stack(t_list **stack, int argc, char **argv)
|
||||
{
|
||||
t_list *new;
|
||||
char **args;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (argc == 2)
|
||||
args = ft_split(argv[1]);
|
||||
else
|
||||
{
|
||||
i = 1;
|
||||
args = argv;
|
||||
}
|
||||
while (args[i])
|
||||
{
|
||||
new = ft_lstnew(ft_atoi(args[i]));
|
||||
ft_lstadd_back(stack, new);
|
||||
i++;
|
||||
}
|
||||
index_stack(stack);
|
||||
if (argc == 2)
|
||||
free_string(args);
|
||||
}
|
||||
|
||||
static void sort_stack(t_list **stack_a, t_list **stack_b)
|
||||
{
|
||||
if (ft_lstsize(*stack_a) <= 5)
|
||||
simple_sort(stack_a, stack_b);
|
||||
else
|
||||
radix_sort(stack_a, stack_b);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_list **stack_a;
|
||||
t_list **stack_b;
|
||||
|
||||
check_args(argv);
|
||||
stack_a = (t_list **)malloc(sizeof(t_list));
|
||||
if (!stack_a)
|
||||
error_message("alloc stack_a", NULL, NULL, NULL);
|
||||
*stack_a = NULL;
|
||||
init_stack(stack_a, argc, argv);
|
||||
if (is_sorted(stack_a) == 1)
|
||||
(free_stack(stack_a), exit(0));
|
||||
stack_b = (t_list **)malloc(sizeof(t_list));
|
||||
*stack_b = NULL;
|
||||
sort_stack(stack_a, stack_b);
|
||||
free_stack(stack_a);
|
||||
free_stack(stack_b);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue