Java uses circular linked list structure to solve Joseph problem

This paper describes the method of solving Joseph problem with circular linked list structure in Java. Share with you for your reference. The specific analysis is as follows:

This is the first java test question. For students who haven't seen the linked list, they won't do it. Now it's really not difficult to look back.

Joseph problem: there are n individuals whose numbers are 1, 2, 3,..., n. The n people are arranged in a circle in order. Now, given s and D, start from the s-th person, count from 1, and the person counting to D will be listed, and then start from the next person, count from 1, and the person counting to D will be listed again. This cycle will last until everyone is listed. It is required to define a node class and use the circular linked list structure to solve the Joseph problem.

The following java version of the answer:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>