got a working sort
This commit is contained in:
parent
428525b561
commit
2d351417dc
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
/* Created: 2019/02/23 13:35:15 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/02 18:28:08 by tmaze ### ########.fr */
|
/* Updated: 2019/03/06 16:08:02 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -48,12 +48,14 @@ int read_ops(t_psdata *data)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ft_memset(buff, '\0', 5);
|
ft_memset(buff, '\0', 5);
|
||||||
while ((ret = read(1, buff, 4)) > 0)
|
while ((ret = read(0, buff, 4)) > 0)
|
||||||
{
|
{
|
||||||
|
printf("buff '%s'\n", buff);
|
||||||
buff[ft_strlen(buff) - 1] = '\0';
|
buff[ft_strlen(buff) - 1] = '\0';
|
||||||
|
printf("buff '%s'\n", buff);
|
||||||
if (ret > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
|
if (ret > 4 || !is_op(buff) || (nop = ft_lstnew(buff, 4)) == NULL)
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error", 2);
|
dprintf(2, "Error op %d %d '%s'", ret > 4, !is_op(buff), buff);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_lstaddend(&(data->op), nop);
|
ft_lstaddend(&(data->op), nop);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
/* Created: 2019/02/25 12:44:08 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/03 13:59:43 by tmaze ### ########.fr */
|
/* Updated: 2019/03/06 16:02:44 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
/* Created: 2019/03/03 11:41:49 by tmaze #+# #+# */
|
||||||
/* Updated: 2019/03/06 12:10:10 by tmaze ### ########.fr */
|
/* Updated: 2019/03/06 15:52:03 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,7 +17,6 @@ int sort(t_psdata *data, int size)
|
|||||||
t_stack *ptr;
|
t_stack *ptr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("start sort %d\n", size);
|
|
||||||
if (size > 2)
|
if (size > 2)
|
||||||
{
|
{
|
||||||
if (!sort(data, ((size % 2) ? size + 1 : size) / 2))
|
if (!sort(data, ((size % 2) ? size + 1 : size) / 2))
|
||||||
@ -26,7 +25,18 @@ int sort(t_psdata *data, int size)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
else if (size == 1)
|
else if (size == 1)
|
||||||
|
{
|
||||||
|
printf("ra\n");
|
||||||
|
ps_rot(data, 'a');
|
||||||
return (1);
|
return (1);
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while (size > 2 && i < size)
|
||||||
|
{
|
||||||
|
printf("rra\n");
|
||||||
|
ps_rerot(data, 'a');
|
||||||
|
i++;
|
||||||
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
ptr = data->a;
|
ptr = data->a;
|
||||||
while (i < ((size % 2) ? size + 1 : size) / 2)
|
while (i < ((size % 2) ? size + 1 : size) / 2)
|
||||||
@ -42,14 +52,6 @@ int sort(t_psdata *data, int size)
|
|||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i = 0;
|
|
||||||
ptr = data->a;
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
printf("@ind %d: nb=%d ind=%d\n", i, ptr->nb, ptr->ind);
|
|
||||||
ptr = ptr->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (data->a->ind == 1)
|
while (data->a->ind == 1)
|
||||||
{
|
{
|
||||||
printf("pb\n");
|
printf("pb\n");
|
||||||
@ -63,25 +65,15 @@ int sort(t_psdata *data, int size)
|
|||||||
}
|
}
|
||||||
while (data->a->ind != 0 || data->size_b > 0)
|
while (data->a->ind != 0 || data->size_b > 0)
|
||||||
{
|
{
|
||||||
printf("data->a->ind %d\ndata->a->nb %d\ndata->size_b %zu\n", data->a->ind, data->a->nb, data->size_b);
|
|
||||||
if ((data->a->ind != 0 && data->size_b > 0 && data->a->nb > data->b->nb)
|
if ((data->a->ind != 0 && data->size_b > 0 && data->a->nb > data->b->nb)
|
||||||
|| (data->a->ind == 0 && data->size_b > 0))
|
|| (data->a->ind == 0 && data->size_b > 0))
|
||||||
{
|
{
|
||||||
printf("pa\n");
|
printf("pa\n");
|
||||||
ps_push(data, 'a');
|
ps_push(data, 'a');
|
||||||
}
|
}
|
||||||
printf("mise a zero:\ndata->a->ind %d\ndata->a->nb %d\n", data->a->ind, data->a->nb);
|
|
||||||
data->a->ind = 0;
|
data->a->ind = 0;
|
||||||
printf("ra\n");
|
printf("ra\n");
|
||||||
ps_rot(data, 'a');
|
ps_rot(data, 'a');
|
||||||
i = 0;
|
|
||||||
ptr = data->a;
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
printf("@ind %d: nb=%d ind=%d\n", i, ptr->nb, ptr->ind);
|
|
||||||
ptr = ptr->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@ -90,6 +82,7 @@ int main(int ac, char **av)
|
|||||||
{
|
{
|
||||||
t_stack *ptr;
|
t_stack *ptr;
|
||||||
t_psdata data;
|
t_psdata data;
|
||||||
|
int i;
|
||||||
|
|
||||||
ps_initdata(&data);
|
ps_initdata(&data);
|
||||||
if (!get_params(&data, ac, av))
|
if (!get_params(&data, ac, av))
|
||||||
@ -108,12 +101,22 @@ int main(int ac, char **av)
|
|||||||
ps_stkclean(&data);
|
ps_stkclean(&data);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ptr = data.a;
|
/* ptr = data.a; */
|
||||||
while (ptr)
|
/* i = data.a->nb; */
|
||||||
{
|
/* while (ptr) */
|
||||||
printf("%d\n", ptr->nb);
|
/* { */
|
||||||
ptr->ind = 0;
|
/* printf("%d\n", ptr->nb); */
|
||||||
ptr = ptr->next;
|
/* ptr->ind = 0; */
|
||||||
}
|
/* if (i != ptr->nb && i > ptr->nb) */
|
||||||
|
/* { */
|
||||||
|
/* printf("KO\n"); */
|
||||||
|
/* break ; */
|
||||||
|
/* } */
|
||||||
|
/* i = ptr->nb; */
|
||||||
|
/* ptr = ptr->next; */
|
||||||
|
/* } */
|
||||||
|
/* if (ptr == NULL) */
|
||||||
|
/* printf("OK\n"); */
|
||||||
|
/* ps_stkclean(&data); */
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user