From 78320824fce283cb14c9adc74f253d6f8ad892fe Mon Sep 17 00:00:00 2001 From: Yaroslav Kolomiets Date: Tue, 20 Dec 2016 20:19:28 +0200 Subject: [PATCH] dancing links fixed --- src/dancing_links.c | 116 +++++++++++++++++++++++--------------------- src/glue_figure.c | 4 +- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/src/dancing_links.c b/src/dancing_links.c index 6d333e7..045784e 100644 --- a/src/dancing_links.c +++ b/src/dancing_links.c @@ -12,67 +12,71 @@ #include "fillit.h" -// t_col *add_column(t_col *root) -// { -// t_col *new_col; +t_node *add_column(t_node *root) +{ + t_node *new_col; -// new_col = (t_col*)malloc(sizeof(t_col)); -// new_col->down = (void*)new_col; -// new_col->up = (void*)new_col; -// new_col->left = root->left; -// new_col->right = root; -// return (new_col); -// } + new_col = (t_node*)malloc(sizeof(t_node)); + new_col->down = new_col; + new_col->up = new_col; + new_col->left = root->left; + new_col->right = root; + new_col->row = -1; + new_col->column = NULL; + return (new_col); +} -// t_node *add_node(t_col *col, int row) -// { -// t_node *new_node; +t_node *add_node(t_node *col, int row) +{ + t_node *new_node; -// new_node = (t_node*)malloc(sizeof(t_node)); -// new_node->row = row; -// new_node->up = (t_node*)col->up; -// new_node->down = (t_node*)col; -// col->up->down = new_node; -// col->up = new_node; -// return (new_node); -// } + new_node = (t_node*)malloc(sizeof(t_node)); + new_node->row = row; + new_node->up = col->up; + new_node->down = col; + col->up->down = new_node; + col->up = new_node; + return (new_node); +} -// void cover(t_col *to_cover) -// { -// void *step_vert; -// t_node *step_horiz; +void cover(t_col *to_cover) +{ + void *step_vert; + t_node *step_horiz; -// to_cover->left->right = to_cover->right; -// to_cover->right->left = to_cover->left; -// step_vert = to_cover->down; -// while (step_vert != (void*)to_cover) -// { -// step_horiz = (t_node*)step_vert->right; -// while (step_horiz != (t_node*)step_vert) { -// step_horiz->down->up = step_horiz->up; -// step_horiz->up->down = step_horiz->down; -// step_horiz = step_horiz->right; -// } -// step_vert = (t_node*)step_vert->down; -// } -// } + to_cover->left->right = to_cover->right; + to_cover->right->left = to_cover->left; + step_vert = to_cover->down; + while (step_vert != to_cover) + { + step_horiz = step_vert->right; + while (step_horiz != step_vert) { + step_horiz->down->up = step_horiz->up; + step_horiz->up->down = step_horiz->down; + step_horiz = step_horiz->right; + } + step_vert = step_vert->down; + } +} -// void uncover(t_col *to_uncover) -// { -// void *step_vert; -// t_node *step_horiz; +void uncover(t_col *to_uncover) +{ + void *step_vert; + t_node *step_horiz; -// step_vert = to_uncover->up; -// while (step_vert != (void*)to_uncover) -// { -// step_horiz = (t_node*)step_vert->left; -// while (step_horiz != (t_node*)step_vert) -// { -// step_horiz->down->up = step_horiz; -// step_horiz->up->down = step_horiz; -// step_horiz = step_horiz->left; -// } -// step_vert = (t_node*)step_vert->up; -// } -// } + step_vert = to_uncover->up; + while (step_vert != to_uncover) + { + step_horiz = step_vert->left; + while (step_horiz != step_vert) + { + step_horiz->down->up = step_horiz; + step_horiz->up->down = step_horiz; + step_horiz = step_horiz->left; + } + step_vert = step_vert->up; + } + to_uncover->left->right = to_uncover; + to_uncover->right->left = to_uncover; +} diff --git a/src/glue_figure.c b/src/glue_figure.c index 07e71b0..e49dc51 100644 --- a/src/glue_figure.c +++ b/src/glue_figure.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/14 17:12:30 by gtertysh #+# #+# */ -/* Updated: 2016/12/14 17:12:32 by gtertysh ### ########.fr */ +/* Updated: 2016/12/20 20:06:22 by ykolomie ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,4 +43,4 @@ char **glue_figure(char **table) free(table[i++]); free(table); return (ttr_table); -} \ No newline at end of file +}