Algorithms and Data Structures and Joseph learning 9- circular linked list problems

List describes unidirectional ring

Linked list pointer field of each node is unidirectional, point to the next node, the last node and the next pointer points to the first node, thus forming a closed loop, such a list structure is a one-way circular linked list, it can for solving Joseph problems
Here Insert Picture Description

Joseph problems

Josephu problem:
set number is l, 2,3, ... n, n individuals sitting around the agreed number k (1 <= k <= n) from a start number of people reported that the personal number to m column, his next and from 1 Countin, that person has a number to m columns, and so on, until all of the columns position, thereby creating a team out of the numbering sequence.

Tips
with a lead node is not a circular list to deal with the problem Josephu: a first configuration with a single cycle n-node list, then starting from the node k 1 begins counting charged to m, corresponding to the node from the list remove, then start at a node is deleted from the node and from a start counting until the last node to delete from the list algorithm ends.

Published 49 original articles · won praise 47 · views 20000 +

Guess you like

Origin blog.csdn.net/mzc_love/article/details/104365454