private static void CircleDelete(ref LinkElem <int> head) { LinkElem <int> now = head; ConsoleWriteList(now); while (now.elem != now.next.elem) { now.next = now.next.next; now = now.next; ConsoleWriteList(now); } head = now; }
private static void CreateCircleOfElem(int n, ref LinkElem <int> head) { LinkElem <int> now = head; now.elem = 1; int i; for (i = 0; i < n - 1; i++) { now.next = new LinkElem <int>(i + 2); now = now.next; } now.next = head; }
static void Main(string[] args) { int n = 0; LinkElem <int> head = new LinkElem <int>(); Console.WriteLine("Введите колличество человек"); while (!int.TryParse(Console.ReadLine(), out n)) { ; } Console.WriteLine(); CreateCircleOfElem(n, ref head); CircleDelete(ref head); Console.WriteLine("Остался элемент под номером {0}", head.elem); Console.ReadKey(); }
public LinkElem(T elem) { this.elem = elem; next = null; }
public LinkElem(LinkElem <T> nextelem, T elem) { this.elem = elem; next = nextelem; }
public LinkElem(LinkElem <T> a) { next = a; }
public LinkElem() { next = null; }