using System; using System.Collections.Generic; namespace ConsoleApplication { class Program { static void Main(string[] args) { Random rnd = new Random(123); LinkedList list = new LinkedList(); for (int i = 0; i < 25; i++) { list.AddLast(rnd.Next(0, 5)); } Console.WriteLine("До:"); foreach (var i in list) { Console.WriteLine(i); } Console.WriteLine(); LinkedListNode node; var d = 0; do { d = 0; node = list.First; while (node != null) { int prev = -9999; int next = -99; if (node.Previous != null) { prev = node.Previous.Value; } if (node.Next != null) { next = node.Next.Value; } var nextNode = node.Next; if (node.Value == prev || prev == next || node.Value == next) { d++; Console.WriteLine("DELETE: Prev:{0} ,Curr:{1}, Next:{2}", prev, node.Value, next); //Удаление элемента list.Remove(node); } node = nextNode; } } while (d != 0); Console.WriteLine(); Console.WriteLine("После:"); foreach (var i in list) { Console.WriteLine(i); } Console.ReadKey(); } } }