Joseph Ring--In a circle, define a value K, start counting from any position, delete the current position node with each k step, until the last node is left, and the last node.
Single-linked list structure and find function see 2016-1-2 13:56 blog post
Slistnode* joseph (slistnode *&pos, int k) //Joseph Ring { assert (POS); if (k > 0) { SListNode *tmp = pos; while (1) { int count = K; while (--count) { tmp = tmp->next; } if (tmp-> NEXT == TMP) return tmp; slistnode *cur = tmp->next;//Delete the node of the TMP location, thinking: Pos and the next location node element value after the exchange, delete the next node datatype tmpcount = cur->data; tmp->next = cur->next; cur->data = tmp->data; tmp->data = tmpcount; free (cur); } } return null;} Void test7 ()// joseph{ printf ("//test7 () joseph \n"); slistnode&nbsP;*ll = null; pushback (ll, 1); pushback (ll, 2); pushback (LL, 3); Pushback (ll, 4); pushback (ll, 5); pushback (ll, 6); pushback (LL, 7); Find (ll, 7)->next = find (ll, 1); printf ("%d\n", joseph (ll, 3)->data);}
650) this.width=650; "title=" Qq20160105000820.png "src=" http://s3.51cto.com/wyfs02/M02/79/2D/ Wkiom1akmsnw3zgmaaac7og2mho188.png "alt=" Wkiom1akmsnw3zgmaaac7og2mho188.png "/>
C + +, data structure single linked list implementation Joseph Ring