Question:17 people are in a circle, starting from the first person to report data, reporting to 3 and leaving until the last person is left to do this with the object-oriented thinking.
I will do this myself.
Public class person {public person Prev {get; set;} public person Next {get; set;} public int Val {get; set;} public person () {} public person (person pre, person next, int val) {Prev = pre; Next = next; Val = val ;}} class Program {static void Main (string [] args) {var rootperson = new person (); rootperson. val = 1; // initialization data person temp = rootperson; for (int I = 2; I <= 17; I ++) {var p = n Ew person (temp, null, I); temp. next = p; temp = p;} temp. next = rootperson; rootperson. prev = temp; // the last connection to the first one // output int j = 1; person start = rootperson; while (start. next! = Null) {if (j % 3 = 0) remove (start); start = start. next; j ++;} Console. readLine ();} public static void remove (person p) // output and exit the chain ring {Console. writeLine (p. val); if (p. prev! = P. next) {p. prev. next = p. next; p. next. prev = p. prev;} else // {p. prev. next = null; p. prev. prev = null ;}}}
Output result:
You may also wish to give your comments.