dancing links method
This commit is contained in:
parent
9cd3acb0d1
commit
9f78ae5810
4 changed files with 126 additions and 19 deletions
3
Makefile
3
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
||||||
# Updated: 2016/12/14 18:41:33 by gtertysh ### ########.fr #
|
# Updated: 2016/12/20 19:05:59 by gtertysh ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ SRC_FILES = main.c \
|
||||||
to_strct_array.c \
|
to_strct_array.c \
|
||||||
to_letters.c \
|
to_letters.c \
|
||||||
build_matrix.c \
|
build_matrix.c \
|
||||||
|
dancing_links.c \
|
||||||
test!_check.c \
|
test!_check.c \
|
||||||
test!_print_one_string.c \
|
test!_print_one_string.c \
|
||||||
test!_print_table.c \
|
test!_print_table.c \
|
||||||
|
|
45
inc/fillit.h
45
inc/fillit.h
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/14 16:42:06 by gtertysh #+# #+# */
|
/* Created: 2016/12/14 16:42:06 by gtertysh #+# #+# */
|
||||||
/* Updated: 2016/12/20 18:59:06 by gtertysh ### ########.fr */
|
/* Updated: 2016/12/20 19:18:00 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -23,14 +23,39 @@
|
||||||
# define BUF_S 8192
|
# define BUF_S 8192
|
||||||
# define HOW_MUCH 10000
|
# define HOW_MUCH 10000
|
||||||
|
|
||||||
|
typedef struct s_coord
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} t_coord;
|
||||||
|
|
||||||
typedef struct s_ttrmn
|
typedef struct s_ttrmn
|
||||||
{
|
{
|
||||||
char t[17];
|
char t[17];
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int coord[4];
|
t_coord c[4];
|
||||||
} t_ttrmn;
|
} t_ttrmn;
|
||||||
|
|
||||||
|
typedef struct s_col
|
||||||
|
{
|
||||||
|
struct s_col *left;
|
||||||
|
struct s_col *right;
|
||||||
|
void *up;
|
||||||
|
void *down;
|
||||||
|
} t_col;
|
||||||
|
|
||||||
|
typedef struct s_node
|
||||||
|
{
|
||||||
|
struct s_node *left;
|
||||||
|
struct s_node *right;
|
||||||
|
struct s_node *up;
|
||||||
|
struct s_node *down;
|
||||||
|
int row;
|
||||||
|
t_col *column;
|
||||||
|
} t_node;
|
||||||
|
|
||||||
|
|
||||||
// reads from file
|
// reads from file
|
||||||
char *read_file(char *path);
|
char *read_file(char *path);
|
||||||
|
|
||||||
|
@ -57,9 +82,13 @@ void test_check(char **ttr, t_ttrmn *tamplates);
|
||||||
void to_letters(char **ttr);
|
void to_letters(char **ttr);
|
||||||
|
|
||||||
// create array of ttr structures
|
// create array of ttr structures
|
||||||
t_ttrmn **to_strct_array(char **ttr, t_ttrmn *templates);
|
int *to_strct_array(char **ttr, t_ttrmn *templates);
|
||||||
|
|
||||||
|
t_col *add_column(t_col *root);
|
||||||
|
t_node *add_node(t_col *col, int row);
|
||||||
|
void cover(t_col *to_cover);
|
||||||
|
void uncover(t_col *to_uncover);
|
||||||
|
|
||||||
|
|
||||||
// build matrix for algorythm X
|
|
||||||
int **build_matrix(t_ttrmn **ttr);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
78
src/dancing_links.c
Normal file
78
src/dancing_links.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* dancing_links.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/20 19:21:42 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2016/12/20 19:22:04 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
// t_col *add_column(t_col *root)
|
||||||
|
// {
|
||||||
|
// t_col *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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// t_node *add_node(t_col *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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
19
src/main.c
19
src/main.c
|
@ -6,18 +6,19 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
|
/* Created: 2016/12/10 16:07:25 by gtertysh #+# #+# */
|
||||||
/* Updated: 2016/12/20 18:59:59 by gtertysh ### ########.fr */
|
/* Updated: 2016/12/20 19:21:09 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
|
|
||||||
// bad global variable
|
// bad global variable
|
||||||
t_ttrmn templates[19] =
|
t_ttrmn g_templates[19] =
|
||||||
{
|
{
|
||||||
{ .t = "#...#...#...#...",
|
{
|
||||||
.x = 1,
|
"#...#...#...#...", 1, 4, .c[0] = {0, 0}, .c[1] = {1, 0},
|
||||||
.y = 4},
|
.c[2] = {2, 0}, .c[3] = {3, 0}
|
||||||
|
},
|
||||||
|
|
||||||
{ .t = "####............",
|
{ .t = "####............",
|
||||||
.x = 4,
|
.x = 4,
|
||||||
|
@ -98,9 +99,8 @@ int main(int argc, char **argv)
|
||||||
char **table;
|
char **table;
|
||||||
char **ttr;
|
char **ttr;
|
||||||
int i;
|
int i;
|
||||||
t_ttrmn **strct_ttr;
|
int *types;
|
||||||
int **matrix;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
|
@ -128,10 +128,9 @@ int main(int argc, char **argv)
|
||||||
//printf("test check:\n\n");
|
//printf("test check:\n\n");
|
||||||
//test_check(ttr, templates);
|
//test_check(ttr, templates);
|
||||||
|
|
||||||
strct_ttr = to_strct_array(ttr, templates);
|
types = to_strct_array(ttr, g_templates);
|
||||||
|
|
||||||
|
|
||||||
matrix = build_matrix(strct_ttr);
|
|
||||||
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
||||||
//to_letters(ttr);
|
//to_letters(ttr);
|
||||||
//printf("to latters:\n\n");
|
//printf("to latters:\n\n");
|
||||||
|
|
Loading…
Reference in a new issue