#include "nq.h" #include "nq_ok.h" #include "nq_smart.h" class NQ_test { public: static void nq_virtual_test(void) { using namespace std; NQ::Seq sq = {3, 6, 4, 2, 8, 5, 7, 1}; char **pp = NQ::build_charpp(8, '.'); NQ::seq_2_charpp(sq, pp); // vector<int>{0,1,2,3,4,5,6,7} NQ_ok a(pp, 8, "Alice"); NQ_ok b(4, "Boss"); NQ_smart c(pp, 8, "Carlos"); NQ_smart d(10); // NQ_smart c, d; NQ *objs[4] = {&a, &b, &c, &d}; NQ *x; for (int j = 0; j < 4; j++) { x = objs[j]; cout << "\n============ x = objs[" << j << "] ================== \n"; cout << "\n ...... cout << x ........ \n"; cout << *x; cout << "\n.... x->check_solution(sq) ... \n"; x->check_solution(sq); cout << "\n.... x->find_one_sol() ... \n"; x->find_one_sol(); cout << "\n.... x->find_all_solutions() ... \n"; x->find_all_sols(); } cout << endl; } }; int main(void) { NQ_test::nq_virtual_test(); return 0; }
时间: 2024-04-27 09:25:17 浏览: 69
这段代码是一个 N 皇后问题的解法实现。其中用到了 NQ、NQ_ok、NQ_smart 三个类,分别代表了不同的解法实现。其中 NQ 是一个基类,NQ_ok 和 NQ_smart 是 NQ 的派生类。代码中通过使用多态的方式,创建了一个 NQ 类型的指针数组,用于存储 NQ、NQ_ok、NQ_smart 三个类的对象,然后通过循环遍历指针数组来操作每个对象,并输出相应的解法结果。
阅读全文
相关推荐















