1. 错误的代码例子:

class Joseph { public: Joseph(int num, int step) { if (num <= 0 || step <= 0) { cout << "Invalid input!" << endl; return; } // ... } // ... };

  1. 错误的代码例子:

class Joseph { public: void run(int n, int m) { if (m > n) { cout << "Invalid input!" << endl; return; } // ... } // ... };

  1. 错误的代码例子:

class Joseph { public: void run(int n, int m) { for (int i = 1; i < m - 1; i++) { // ... } // ... } // ... };

1 在 Joseph 类的构造函数中如果输入的人数 num 小于等于 0 或者步长 step 小于等于 0那么程序将无法正常运行。 2 在 Joseph 类的 run 函数中如果输入的步长 m 大于人数 n那么程序将进入死循环无法正常结束。 3 在 Joseph 类的 run 函数中循环中的语句 for int i = 1; i m - 1; i++ 中应该是 i m要删除的节点是第 m 个节

原文地址: https://www.cveoy.top/t/topic/bqjw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录