only gets better B)
ditched GNL for ft_getline in checker norm cleanup
This commit is contained in:
100
srcs/ps_sorttools.c
Normal file
100
srcs/ps_sorttools.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_sorttools.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/16 13:23:27 by tmaze #+# #+# */
|
||||
/* Updated: 2019/03/16 13:23:57 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void mark_groups(t_psdata *data)
|
||||
{
|
||||
t_stack *ptr;
|
||||
int inds;
|
||||
|
||||
ptr = data->a;
|
||||
inds = 1;
|
||||
while (ptr)
|
||||
{
|
||||
ptr->ind = inds;
|
||||
if (ptr->next && ptr->nb > ptr->next->nb)
|
||||
inds++;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
t_stack *get_last_a(t_psdata *data)
|
||||
{
|
||||
t_stack *ptr;
|
||||
|
||||
ptr = data->a;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
int get_size_firsts(t_psdata *data)
|
||||
{
|
||||
t_stack *ptr;
|
||||
int inds;
|
||||
int i;
|
||||
|
||||
inds = data->a->ind;
|
||||
i = 0;
|
||||
ptr = data->a;
|
||||
while (ptr && ptr->ind == inds && (i += 1))
|
||||
ptr = ptr->next;
|
||||
if (ptr)
|
||||
{
|
||||
inds = ptr->ind;
|
||||
while (ptr && ptr->ind == inds && (i += 1))
|
||||
ptr = ptr->next;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int get_size_last(t_psdata *data)
|
||||
{
|
||||
t_stack *ptr;
|
||||
int inds;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
ptr = data->a;
|
||||
while (ptr && ptr->next)
|
||||
ptr = ptr->next;
|
||||
inds = ptr->ind;
|
||||
ptr = data->a;
|
||||
while (ptr)
|
||||
{
|
||||
i += (ptr->ind == inds) ? 1 : 0;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int get_nb_groups(t_psdata *data)
|
||||
{
|
||||
t_stack *ptr;
|
||||
int ind;
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
ptr = data->a;
|
||||
ind = ptr->ind;
|
||||
while (ptr)
|
||||
{
|
||||
if (ret == 0 || ptr->ind != ind)
|
||||
{
|
||||
ret++;
|
||||
ind = ptr->ind;
|
||||
}
|
||||
ptr = ptr->next;
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
Reference in New Issue
Block a user