当前位置: 首页 > 科技观察

Java编程内功——数据结构与算法《环表与约瑟夫问题》

时间:2023-03-12 16:09:33 科技观察

在Josephhu问题中,假设n个人编号为1,2,....n坐成一圈,编号为k(1<nums){System.out.println("参数输入错误,请重新输入");return;}//创建辅助帮助孩子出圈的指针boyhelper=first;//让helper指向循环链表的最后一个节点while(helper.getNext()!=first){helper=helper.getNext();}//在计数之前,让helper和first移动,移动k-1次,使得first位于最开始的Node,helper在其后byfirstfor(inti=0;i