sort5 not working
This commit is contained in:
parent
327f5a296d
commit
bb8ea578a6
58
src/sort/sort5.c
Normal file
58
src/sort/sort5.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* sort5.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2024/11/07 15:17:36 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2024/11/07 15:57:09 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
#include "push_swap.h"
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
int rotate_a_to_top(t_state *state)
|
||||||
|
{
|
||||||
|
while (*(int *) state->a->content != stack_min(state->a))
|
||||||
|
ra(state);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int merge_to_a(t_state *state)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = ft_lstsize(state->a);
|
||||||
|
if (*(int *) state->b->content < stack_min(state->a))
|
||||||
|
pa(state);
|
||||||
|
else if (*(int *) state->b->content > stack_max(state->a))
|
||||||
|
{
|
||||||
|
rotate_a_to_top(state);
|
||||||
|
pa(state);
|
||||||
|
rra(state);
|
||||||
|
}
|
||||||
|
while (*((int *) state->b->content) > *((int *) state->a->content) && n > 0)
|
||||||
|
{
|
||||||
|
rra(state);
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
pa(state);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sort5(t_state *state)
|
||||||
|
{
|
||||||
|
pb(state);
|
||||||
|
pb(state);
|
||||||
|
if (*(int *)state->b->content < *(int *)state->b->next->content)
|
||||||
|
sb(state);
|
||||||
|
sort3(state);
|
||||||
|
merge_to_a(state);
|
||||||
|
merge_to_a(state);
|
||||||
|
while (*(int *) state->a->content > *(int *) ft_lstlast(state->a)->content)
|
||||||
|
rra(state);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
29
src/util/stack_max.c
Normal file
29
src/util/stack_max.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* stack_max.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2024/11/07 16:29:41 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2024/11/07 16:36:40 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int stack_max(t_list *lst)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
while (lst->next)
|
||||||
|
{
|
||||||
|
if (*(int *) lst->content > n)
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
if (*(int *) lst->content > n)
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
29
src/util/stack_min.c
Normal file
29
src/util/stack_min.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* stack_min.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2024/11/07 16:29:41 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2024/11/07 16:35:59 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int stack_min(t_list *lst)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
while (lst->next)
|
||||||
|
{
|
||||||
|
if (*(int *) lst->content < n)
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
if (*(int *) lst->content < n)
|
||||||
|
n = *(int *) lst->content;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user