From 09548ce411ad90b1ceddb9cf79f362bf594efbd6 Mon Sep 17 00:00:00 2001 From: Trygve Date: Wed, 13 Mar 2024 01:52:23 +0100 Subject: [PATCH] 22 --- lab_3/21_and_22/queens.cpp | 10 ++++++++++ lab_3/21_and_22/queens.hh | 12 ++++++++++++ lab_3/21_and_22/test.cpp | 22 +++++++++++++--------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lab_3/21_and_22/queens.cpp b/lab_3/21_and_22/queens.cpp index f577398..8823845 100644 --- a/lab_3/21_and_22/queens.cpp +++ b/lab_3/21_and_22/queens.cpp @@ -28,6 +28,16 @@ Configuration::Configuration(int m, int n, int number_of_pieces) { } } +Configuration::~Configuration() +{ + delete this->board; +} +/* +Configuration::Configuration(Configuration& t) +{ + this->board = t.board; +} +*/ std::vector Configuration::get_conflicts() { std::vector conflicts; diff --git a/lab_3/21_and_22/queens.hh b/lab_3/21_and_22/queens.hh index 8af8c96..fd323fb 100644 --- a/lab_3/21_and_22/queens.hh +++ b/lab_3/21_and_22/queens.hh @@ -41,6 +41,18 @@ namespace queens Board* board; Configuration(int m, int n, int number_of_pieces); + ~Configuration(); + + // I could not get copy constructor and copy assignment operator to work :/ + //Configuration(Configuration& t); + /* + + Configuration& operator=(const Configuration& rhs) + { + this->board = rhs.board; + return *this; + } + */ std::vector get_conflicts(); }; diff --git a/lab_3/21_and_22/test.cpp b/lab_3/21_and_22/test.cpp index 54c082c..b060e6e 100644 --- a/lab_3/21_and_22/test.cpp +++ b/lab_3/21_and_22/test.cpp @@ -1,5 +1,7 @@ +#include #include "queens.hh" #include +#include void print_conflict(queens::Conflict c) { @@ -8,14 +10,16 @@ void print_conflict(queens::Conflict c) } int main() -{ - queens::Configuration config = queens::Configuration(8, 8, 10); - std::vector conflicts = config.get_conflicts(); - for (int i=0; i conflicts = config.get_conflicts(); + auto t1 = std::chrono::high_resolution_clock::now(); + log << 1.0e-06 * std::chrono::duration_cast(t1-t0).count() << "\n"; + } + log.close(); } \ No newline at end of file