sort3 start

This commit is contained in:
whaffman 2024-11-07 13:34:01 +01:00
parent 5cad71fcd3
commit 05daa6c06e
5 changed files with 64 additions and 7 deletions

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ #
# +#+ +#+#+ +#++#+ +#+ \o/ #
# Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | #
# Updated: 2024/11/06 20:10:28 by whaffman ### ### ### ### / \ #
# Updated: 2024/11/07 12:48:24 by whaffman ### ### ### ### / \ #
# #
# **************************************************************************** #
@ -64,11 +64,12 @@ re: fclean all
run: all
@$(eval ARG = $(shell shuf -i 0-100 -n 5))
./$(NAME) 1 2 3 4 5 6 7 8 9
./$(NAME) $(ARG)
debug: CFLAGS += -DDEBUG -g
debug: all
debug: fclean
@echo $(CFLAGS)
@$(MAKE) re
@$(MAKE) -C libft debug
@$(MAKE) -s
.PHONY: all bonus clean fclean re

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/04 13:58:35 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/06 20:10:14 by whaffman ### ### ### ### / \ */
/* Updated: 2024/11/07 13:12:32 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
@ -15,6 +15,12 @@
# include "libft.h"
typedef struct s_state
{
t_list *a;
t_list *b;
} t_state;
int new_element(t_list **stack, const char *str);
t_list *ft_lstat(t_list *list, int n);
void print_stack(const char *name, t_list *stack);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/04 13:04:11 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/06 20:11:40 by whaffman ### ### ### ### / \ */
/* Updated: 2024/11/07 13:33:13 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
@ -38,8 +38,10 @@ void print_stack(const char *name, t_list *stack)
void print_stacks(t_list *stack_a, t_list *stack_b)
{
ft_printf("\n");
print_stack("A", stack_a);
print_stack("B", stack_b);
ft_printf("===================\n");
}
int main(int argc, char *argv[])

48
src/sort/sort3.c Normal file
View File

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* sort3.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/07 12:09:48 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/07 13:33:18 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "push_swap.h"
// abc
// acb rra sa
// bca rra
// bac sa
// cab ra
// cba sa rra
int sort3(t_list **stack)
{
const int a = *((int *)(*stack)->content);
const int b = *((int *)(*stack)->next->content);
const int c = *((int *)(*stack)->next->next->content);
if (ft_lstsize(*stack) != 3)
return (0);
if (a < b && b < c)
return (1);
else if (a < b && b > c)
{
rra();
if (a > b)
sa();
}
else if (a > c && b < c)
ra();
else
{
sa();
if (b > c)
rra();
}
return (1);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/11/06 19:19:32 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/11/06 19:37:28 by whaffman ### ### ### ### / \ */
/* Updated: 2024/11/07 13:18:48 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */