Php code for solving the Joseph problem using a ring linked list:
// Circular linked list/* solve the Joseph problem and set the number of persons starting from 1-N according to the number of individuals starting from k to report the number from 1, and report the number to the person from m. His next digit starts counting from 1, and the person counting to M goes out again, and so on until all the people come out of the column and find the column order, and the last column number */header ("content-type: text/html; charset = utf-8"); class Child {public $ no; public $ next = null; public function _ construct ($ no) {$ this-> no = $ no ;}} function addChild (& $ first, $ n) {$ cur = null; for ($ I = 0; $ I <= $ n-1; $ I ++) {$ child = new child ($ I + 1); if ($ I = 0) {$ first = $ child; $ first-> next = $ child; $ cur = $ first;} else {$ cur-> next = $ child; $ child-> next = $ fi Rst; $ cur = $ cur-> next ;}} function showChild ($ first) {$ cur = $ first; while ($ cur-> next! = $ First) {echo $ cur-> no; $ cur = $ cur-> next;} echo $ cur-> no;} function countChild ($ first, $ m, $ k) {$ tail = $ first; // consider starting from the first few children for ($ I = 0; $ I <M-1; $ I ++) {$ tail = $ tail-> next;} while ($ tail-> next! = $ Tail) // remove to the linked list only one element until {for ($ I = 0; $ I <$ K-1; $ I ++) {$ cur = $ tail; // record his previous position $ tail = $ tail-> next;} echo 'column output '. $ tail-> no; $ cur-> next = $ tail-> next; $ tail = $ tail-> next;} echo '123 '. $ tail-> no;} addChild ($ first, 10); showChild ($ first); echo"
"; CountChild ($ first, 2, 3); // count the number of the second child to three