typedef for the moves function array

This commit is contained in:
Willem Haffmans 2024-11-24 22:12:34 +00:00
parent a84e797e89
commit 607ce0db6a
3 changed files with 16 additions and 12 deletions

View File

@ -41,7 +41,7 @@ CC = cc
RM = rm -rf
INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH)
CFLAGS = -Wall -Wextra -Werror -g
CFLAGS = -Wall -Wextra -Werror
LDFLAGS = -L./libft
LDLIBS = -lft
@ -89,4 +89,4 @@ debug: fclean
@$(MAKE) -C libft debug
@$(MAKE) -s
.PHONY: all bonus clean fclean re
.PHONY: all bonus clean fclean re run debug

View File

@ -21,6 +21,8 @@ typedef struct s_state
t_list *b;
} t_state;
typedef void (*t_move)(t_state *, int);
int *longest_incremental_subsequence(t_list *stack, int *lis_size);
int *lis_lengths(t_list *stack, int size);
int *lis_indices(int *lengths, int size, int max_len);

View File

@ -14,13 +14,15 @@
#include <unistd.h>
#include <stdlib.h>
void execute_move(const char *move, t_state *state)
void execute_move(const char *move, t_state *state)
{
void (*const moves[])(t_state *, int) = {&sa, &sb, &ss, &pa, &pb, \
&ra, &rb, &rr, &rra, &rrb, &rrr};
const char *moves_names[] = {"sa\n", "sb\n", "ss\n", "pa\n", "pb\n", \
"ra\n", "rb\n", "rr\n", "rra\n", "rrb\n", "rrr\n"};
int i;
const t_move moves[11] = {&sa, &sb, &ss, &pa, &pb, \
&ra, &rb, &rr, &rra, &rrb, &rrr};
const char *moves_names[] = {"sa\n", "sb\n", "ss\n", \
"pa\n", "pb\n", \
"ra\n", "rb\n", "rr\n", \
"rra\n", "rrb\n", "rrr\n"};
int i;
i = 0;
while (i < 11)
@ -28,7 +30,7 @@ void execute_move(const char *move, t_state *state)
if (ft_strcmp(move, moves_names[i]) == 0)
{
moves[i](state, 1);
return;
return ;
}
i++;
}
@ -37,7 +39,7 @@ void execute_move(const char *move, t_state *state)
int main(int argc, char *argv[])
{
int size;
int size;
t_state *state;
char *move;
@ -47,9 +49,9 @@ int main(int argc, char *argv[])
{
if (!new_element(&(state->a), argv[argc]))
return (error(state));
if (has_duplicates(state->a))
return (error(state));
}
if (has_duplicates(state->a))
return (error(state));
size = ft_lstsize(state->a);
move = get_next_line(STDIN_FILENO);
while (move)