a la norme
This commit is contained in:
27
srcs/algo.c
27
srcs/algo.c
@@ -1,33 +1,7 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
t_list *dup_n_fill(t_stack *a)
|
||||
{
|
||||
t_list *sort;
|
||||
int *i;
|
||||
int j;
|
||||
|
||||
j = 0;
|
||||
sort = NULL;
|
||||
while(a)
|
||||
{
|
||||
i = (int *)ft_calloc(3, sizeof(int));
|
||||
i[0] = a->n;
|
||||
i[1] = j;
|
||||
i[2] = 0;
|
||||
ft_lstadd_back(&sort, ft_lstnew(i));
|
||||
a = a->next;
|
||||
j++;
|
||||
}
|
||||
return (sort);
|
||||
}
|
||||
|
||||
void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
{
|
||||
(void)b;
|
||||
(void)a;
|
||||
(void)solution;
|
||||
|
||||
sa(a, &solution);
|
||||
pb(b, a, &solution);
|
||||
pb(b, a, &solution);
|
||||
@@ -45,4 +19,3 @@ void hugo_sort(t_stack **a, t_stack **b, t_list *solution)
|
||||
rb(b, &solution);
|
||||
rr(a, b, &solution);
|
||||
}
|
||||
|
||||
|
||||
10
srcs/print.c
10
srcs/print.c
@@ -1,8 +1,8 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
/*
|
||||
** this function fill a new element on the chained list like this :
|
||||
** this function is called by actions like sa()
|
||||
** it fills 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) :
|
||||
@@ -10,7 +10,7 @@
|
||||
** a: nb nb nb nb nb
|
||||
** b: nb nb nb
|
||||
**
|
||||
** or only "name" if not flag -p
|
||||
** or only "name" if no flag -p
|
||||
*/
|
||||
void fill_solution(t_list *solution, char *sp)
|
||||
{
|
||||
@@ -21,14 +21,14 @@ void fill_solution(t_list *solution, char *sp)
|
||||
a = *(t_stack **)(solution->content);
|
||||
b = *(t_stack **)(solution->next->content);
|
||||
stack = ft_strjoinfree(ft_strdup(sp), ft_strdup("!a:"));
|
||||
while(a != NULL)
|
||||
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)
|
||||
while (b != NULL)
|
||||
{
|
||||
stack = ft_strjoinfree(stack, ft_strdup(" "));
|
||||
stack = ft_strjoinfree(stack, ft_itoa(b->n));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void push(t_stack **dst, t_stack **src)
|
||||
@@ -15,14 +14,14 @@ void push(t_stack **dst, t_stack **src)
|
||||
*dst = tmp1;
|
||||
}
|
||||
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||
t_list *pa(t_stack **a, t_stack **b, t_list **solution)
|
||||
{
|
||||
push(a, b);
|
||||
fill_solution(*solution, "pa");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
||||
t_list *pb(t_stack **b, t_stack **a, t_list **solution)
|
||||
{
|
||||
push(b, a);
|
||||
fill_solution(*solution, "pb");
|
||||
|
||||
@@ -37,8 +37,6 @@ t_stack *init_stack(int ac, char **av)
|
||||
|
||||
// the chained list "solution" is created with specials first two elements :
|
||||
// they are pointers to stack a and b, so it can be accessed by fill_solution()
|
||||
|
||||
// bubble_sort(&a, &b, solution);
|
||||
t_list *launch_algo(t_stack **a, t_stack **b, int flag)
|
||||
{
|
||||
t_list *solution;
|
||||
@@ -50,6 +48,7 @@ t_list *launch_algo(t_stack **a, t_stack **b, int flag)
|
||||
hugo_sort(a, b, solution);
|
||||
return (solution);
|
||||
}
|
||||
// bubble_sort(&a, &b, solution);
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void rotate(t_stack **stack)
|
||||
void rotate(t_stack **stack)
|
||||
{
|
||||
t_stack *tmp;
|
||||
t_stack *first;
|
||||
@@ -17,25 +16,24 @@ void rotate(t_stack **stack)
|
||||
first->next = NULL;
|
||||
}
|
||||
|
||||
t_list *ra(t_stack **a, t_list **lst)
|
||||
t_list *ra(t_stack **a, t_list **lst)
|
||||
{
|
||||
rotate(a);
|
||||
fill_solution(*lst, "ra");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *rb(t_stack **b, t_list **lst)
|
||||
t_list *rb(t_stack **b, t_list **lst)
|
||||
{
|
||||
rotate(b);
|
||||
fill_solution(*lst, "rb");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
t_list *rr(t_stack **a, t_stack **b, t_list **lst)
|
||||
t_list *rr(t_stack **a, t_stack **b, t_list **lst)
|
||||
{
|
||||
rotate(a);
|
||||
rotate(b);
|
||||
fill_solution(*lst, "rr");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user