# 循环双链表演示约瑟夫环java

package Cir_Double_list;

import java.util.Arrays;
import java.util.Scanner;

public class my_Cir_double_list<T>
{
int length;
public my_Cir_double_list()
{
length=0;
}
public my_Cir_double_list(T[] values)
{
this();
this.length=values.length;
for (T value : values)
{
rearnode.next = new DoubleNode<T>(value, rearnode, null);
rearnode = rearnode.next;
}
}

@Override
public String toString()
{
String str = this.getClass().getName()+"(";
//            str += p.date.toString()+(p.next!=null?"," : "");
{
str += (p.date!=null ? p.date.toString() : "null")+(p.next!=null?"," : "null");//增加了输出时空数据的容错
}
return str+")";
}

public static my_Cir_double_list<Integer> outlist()
{
Integer [] x={1,2,3,4,5,6,7,8,9};
return new my_Cir_double_list<>(x);
}
public static void Josephus_show(int length,int distance)//约瑟夫环演示
{
distance--;
Integer[] jose = new Integer[length];
for (int x=0 ; x<length ; x++)
{
jose[x]=x+1;
}
System.out.println(Arrays.toString(jose));
int falg = 0;
do
{
falg++;
for (int i = 0; i < distance; i++)
{
else
start_node = start_node.next;
}
//--------------------
{
{
start_node = start_node.next;
} else
{
start_node = start_node.next;

start_node.prev.prev.next = start_node;
start_node.prev = start_node.prev.prev;
}
//----------------------
System.out.println("第" + falg + "次结果" + linkedlist);
try
{
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
System.out.println("约瑟夫环演示：");
Josephus_show(41,3);
while (true)
{
System.out.print("请输入长度：(输入0结束)");
Scanner inlenth = new Scanner(System.in);
Scanner indistance = new Scanner(System.in);
int lenth,distance;
lenth= inlenth.nextInt();
if (lenth==0)
return;
System.out.print("请输入距离：");
distance = indistance.nextInt();
Josephus_show(lenth,distance);
}
}
}


• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
12-23 325
05-06 2223
09-24 1643
10-24 2394
11-13
06-22 598
08-09 409
08-31 6941
08-05 2390
02-06 2万+
12-20 2447
08-28 1037

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。