-
Notifications
You must be signed in to change notification settings - Fork 2
/
DancingLinks.h
53 lines (39 loc) · 1.32 KB
/
DancingLinks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef DANCINGLINKS_H
#define DANCINGLINKS_H
#include <iostream>
#include <vector>
#include <ctime>
#include <sstream>
#include "Node.h"
#include "DLXConstants.h"
class DancingLinks {
private:
Node dlxHead;
Node* dlxHeadNode;
Node* solution[MAX_SOLUTIONS];
Node* originalValues[MAX_SOLUTIONS];
bool isSolved;
int Grid[SIZE][SIZE] = { {0} };
clock_t timer1, timer2;
public:
DancingLinks();
~DancingLinks();
// Dancing Links Algorithm Implementation
void coverColumn(Node* column);
void uncoverColumn(Node* column);
void search(int n);
// Build Exact Cover Matrix (each constraint is a column)
void buildExactCoverMatrix(bool grid[NUM_ROWS][NUM_COLS]);
// Build Doubly Linked List (from the exact cover matrix)
void buildDoublyLinkedList(bool grid[NUM_ROWS][NUM_COLS]);
// Transform the current grid to a list of constraints
//void transformListToCurrentGrid(int Puzzle[][SIZE]);
void transformListToCurrentGrid(int sudoku[][SIZE]);
// Once a solution is found, maps the current solution from the linked list back to the Sudoku grid format
void mapSolutionToGrid(int sudoku[][SIZE]);
// Wrapper function to take in a SudokuBoard object and solve it using DLX
void solveSudoku(int sudoku[][SIZE]);
void printGridWithBorders(int sudoku[][SIZE]);
void printMemberGrid() { printGridWithBorders(Grid); }
};
#endif