public class Demo3 {
public static void Main (string[] args) {
Cyclink cyclink=new Cyclink ();
Cyclink.setlen (10);
Cyclink.createlink ();
Cyclink.show ();
CYCLINK.SETK (3);
Cyclink.setm (3);
Cyclink.play ();
}
}
Class Child
{
int no;
Child Nextchild=null;
public child (int no)
{
Give a number
This.no=no;
}
}
Ring Linked List
Class Cyclink
{
First define a reference to the first child in the list
A reference to the first child cannot move
Child Firstchild=null;
Child Temp=null;
It means there are a few children
int len=0;
int k=0;
int m=0;
Determining the step size of a number m
public void Setm (int m)
{
This.m=m;
}
Set the list size
public void Setlen (int len)
{
This. Len=len;
}
Set the number of people starting from the first few
public void setk (int k)
{
This.k=k;
}
Start play
public void Play ()
{
Child Temp=this.firstchild;
First, find the person who started counting.
for (int i=1;i<k;i++)
{
Temp=temp.nextchild;
}
while (this. Len!=1)
{
2. Several m under
for (int j=1;j<m;j++)
{
Temp=temp.nextchild;
}
Find the first child to be out of the loop
Child Temp2=temp;
while (temp2.nextchild! = temp)
{
Temp2=temp2.nextchild;
}
3. Pull the number of children out of the circle
Temp2.nextchild=temp.nextchild;
Let temp point to the next number of kids.
Temp=temp.nextchild;
This. len--;
}
The Last Child
System.out.println ("The last child out of the lap is:" +temp.no);
}
Initialize the ring list
public void Createlink ()
{
for (int i=1;i<=len;i++)
{
Create the first child
if (i==1)
{
Child ch=new Child (i);
This.firstchild=ch;
This.temp=ch;
}
Else
{
if (i! = Len)
{
Continue to create child
Child ch=new Child (i);
Temp.nextchild=ch;
Temp=ch;
Temp.nextchild=this.firstchild;
}
Else
{
Continue to create child
Child ch=new Child (i);
Temp.nextchild=ch;
Temp=ch;
}
}
}
}
Print the ring link
public void Show ()
{
Define a walk-in
Child Temp=this.firstchild;
Do
{
System.out.println (temp.no);
Temp=temp.nextchild;
}while (temp! = This.firstchild);
}
}
Exception in thread "main" Java.lang.Error: Unresolved compilation issue: