#include "push_swap.h" /* ** this function fill a new element on the chained list like this : ** name!a: nb nb nb nb nb!b: nb nb nb ** ** it will later be printed like this ("!" is the char to split) : ** name ** a: nb nb nb nb nb ** b: nb nb nb ** ** or only "name" if not flag -p */ void fill_solution(t_list *solution, char *sp) { t_stack *a; t_stack *b; char *stack; a = *(t_stack **)(solution->content); b = *(t_stack **)(solution->next->content); stack = ft_strjoinfree(ft_strdup(sp), ft_strdup("!a:")); while(a != NULL) { stack = ft_strjoinfree(stack, ft_strdup(" ")); stack = ft_strjoinfree(stack, ft_itoa(a->n)); a = a->next; } stack = ft_strjoinfree(stack, ft_strdup("!b:")); while(b != NULL) { stack = ft_strjoinfree(stack, ft_strdup(" ")); stack = ft_strjoinfree(stack, ft_itoa(b->n)); b = b->next; } ft_lstadd_back(&solution, ft_lstnew(stack)); } void print_result(t_list *result, int flag) { char **part; result = result->next->next; while (result) { part = ft_split(result->content, '!'); ft_printf("%s\n", part[0]); if (flag) { ft_printf(" %s\n", part[1]); ft_printf(" %s\n", part[2]); } result = result->next; free(part[0]); free(part[1]); free(part[2]); free(part); } }