optimised it a bit and now it's better ^^
optimised sort by sorting shorted groups together instead of merging all of them into one
This commit is contained in:
parent
b993e0e68a
commit
735c6af817
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
||||
/* Updated: 2019/03/10 15:17:33 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/03/10 22:36:06 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -112,6 +112,46 @@ t_stack *get_last_a(t_psdata *data)
|
||||
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 sort2(t_psdata *data)
|
||||
{
|
||||
t_list *tmp;
|
||||
@ -147,6 +187,18 @@ int sort2(t_psdata *data)
|
||||
last = get_last_a(data);
|
||||
}
|
||||
}
|
||||
if (data->a->ind != last->ind && add_op(data, "rra") == NULL)
|
||||
return (0);
|
||||
else if (data->a->ind != last->ind)
|
||||
{
|
||||
ps_rerot(data, 'a');
|
||||
last = get_last_a(data);
|
||||
while (last->ind == data->a->ind && (tmp = add_op(data, "rra")) != NULL)
|
||||
{
|
||||
ps_rerot(data, 'a');
|
||||
last = get_last_a(data);
|
||||
}
|
||||
}
|
||||
inds++;
|
||||
}
|
||||
return (1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user