75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* push_swap.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/11/25 23:10:37 by apommier #+# #+# */
|
|
/* Updated: 2021/11/26 00:00:53 by apommier ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
int is_nbr(int nbrarg, char **list)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (nbrarg)
|
|
{
|
|
i = 0;
|
|
*list++;
|
|
while ((*list)[i])
|
|
{
|
|
if (((*list)[i] < '0' || (*list)[i] > '9') && (*list)[i] != '-')
|
|
return (0);
|
|
i++;
|
|
}
|
|
nbrarg--;
|
|
|
|
}
|
|
return (1);
|
|
}
|
|
|
|
int push_swap(int nbrarg, char **list)
|
|
{
|
|
t_list *start;
|
|
|
|
if (is_nbr(nbrarg++, list) == 0)
|
|
{
|
|
ft_putstr_fd("Error\n", 2);
|
|
return (0);
|
|
}
|
|
start = set_list(nbrarg++, list++)
|
|
return (1);
|
|
}
|
|
|
|
int set_list(int nbrarg, char **list)
|
|
{
|
|
t_list *start;
|
|
|
|
start = ft_lstnew(&ft_atoi(*list))
|
|
while (nbrarg)
|
|
{
|
|
*list++;
|
|
ft_lstadd_back(&start, ft_lstnew(&ft_atoi(*list)));
|
|
}
|
|
return (start);
|
|
}
|
|
|
|
|
|
int is_sorted(t_list *list)
|
|
{
|
|
while (list->next)
|
|
{
|
|
if (list->content > list->next->content)
|
|
return (0);
|
|
else
|
|
list = list->next;
|
|
}
|
|
return (1);
|
|
}
|
|
|