2022-12-09 09:22:02 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_bozo_sort.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2022/12/09 14:24:03 by cchauvet #+# #+# */
|
2022-12-09 13:13:15 -05:00
|
|
|
/* Updated: 2022/12/09 19:11:58 by cchauvet ### ########.fr */
|
2022-12-09 09:22:02 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "pushswap.h"
|
|
|
|
|
|
|
|
void ft_bozo_sort(t_tab tab_a, t_tab tab_b)
|
|
|
|
{
|
|
|
|
if (ft_is_sorted(tab_a))
|
|
|
|
return ;
|
2022-12-09 13:13:15 -05:00
|
|
|
while (ft_tablen(tab_a) > 3)
|
2022-12-09 09:22:02 -05:00
|
|
|
{
|
2022-12-09 13:13:15 -05:00
|
|
|
while ((long) tab_a[0] >= ft_tablen(tab_a) + ft_tablen(tab_b) - 3)
|
2022-12-09 09:22:02 -05:00
|
|
|
ft_ra(tab_a);
|
|
|
|
ft_pb(tab_a, tab_b);
|
|
|
|
}
|
2022-12-09 13:13:15 -05:00
|
|
|
if (tab_a[0] == tab_a[1] - 1)
|
|
|
|
ft_rra(tab_a);
|
|
|
|
if (tab_a[0] == tab_a[1] + 1 && tab_a[1] == tab_a[2] + 1)
|
|
|
|
{
|
2022-12-09 09:22:02 -05:00
|
|
|
ft_ra(tab_a);
|
2022-12-09 13:13:15 -05:00
|
|
|
ft_sa(tab_a);
|
|
|
|
}
|
|
|
|
if (tab_a[0] == tab_a[1] + 1)
|
|
|
|
ft_sa(tab_a);
|
2022-12-09 09:22:02 -05:00
|
|
|
if (!ft_is_sorted(tab_a))
|
2022-12-09 13:13:15 -05:00
|
|
|
{
|
|
|
|
ft_pb(tab_a, tab_b);
|
|
|
|
if (!ft_is_sorted(tab_a))
|
|
|
|
ft_ra(tab_a);
|
|
|
|
ft_pa(tab_a, tab_b);
|
|
|
|
if (!ft_is_sorted(tab_a))
|
|
|
|
ft_ra(tab_a);
|
|
|
|
}
|
|
|
|
if (ft_is_sorted(tab_b) && ft_tablen(tab_b) > 1)
|
|
|
|
ft_rb(tab_b);
|
2022-12-09 09:22:02 -05:00
|
|
|
while (ft_tablen(tab_b) != 0)
|
|
|
|
ft_pa(tab_a, tab_b);
|
|
|
|
}
|