Joseph's ring Problem
There are 30 people who will delete their numbers from the beginning, numbers 1, 2, and 3, and delete them every 3. A total of 15 numbers are deleted. Output The number of 15 deleted items
# Include <iostream> using namespace STD; struct linklist {int val; linklist * Next; linklist (int A): Val (A), next (null ){}}; linklist * creatlist (int n) {linklist * P = new linklist (1); linklist * H = P; For (INT I = 2; I <= N; I ++) {linklist * P1 = new linklist (I); P-> next = p1; P = p-> next;} p-> next = H; return h ;} void del () // a total of 30 people, 15 people to be deleted, the number of deleted output {linklist * H = creatlist (30 ); // create a 30-node linked list int num = 15; linklist * P = H, * P1 = H; while (Num) {num --; P = p-> next; cout <p-> next-> Val <""; P1 = p-> next; Delete P-> next; P-> next = p1; P = p1 ;}cout <Endl;} void main () {del ();}