One point that comes to mind for a C # computer question

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.