/// <summary> /// Тело работы с листом по 1ой лабе /// </summary> /// <param name="list"></param> private void Body(DoublyList <int> list) { while (true) { var exit = false; WriteWhatWant(); var answer = GetAnswer(); if (answer == null) { continue; } switch (answer) { case 1: WriteDoublyList(list); break; case 2: WriteReverseDoublyList(list); break; case 3: FindInDoublyList(list); break; case 4: ReverseFindInDoublyList(list); break; case 5: AddAfter(ref list); break; case 6: AddBefore(ref list); break; case 7: Delete(ref list); break; case 0: exit = true; break; default: Console.WriteLine("Такого значения нет! Попробуй еще раз..."); break; } if (exit) { break; } } }
/// <summary> /// Вывод обратного листа на экран /// </summary> /// <param name="list"></param> private void WriteReverseDoublyList(DoublyList <int> doublyList) { var list = doublyList.GetReversList(); Console.Write("Все элементы в обратном порядке: "); WriteList(list); }
/// <summary> /// Вывод листа на экран /// </summary> /// <param name="list"></param> private void WriteDoublyList(DoublyList <int> doublyList) { var list = doublyList.GetList(); Console.Write("Все элементы: "); WriteList(list); }
public void ClearTest() { DoublyList <int> list = new DoublyList <int>(); for (int i = 1; i <= 5; i++) { ; } list.Clear(); }
/// <summary> /// Инициализация листа /// </summary> /// <returns></returns> private DoublyList <int> InitDoublyList() { var list = new DoublyList <int>(); for (var i = 0; i < ValueCount; i++) { list.Add(RandomValue()); } return(list); }
public void AddLastTest() { DoublyList <int> list = new DoublyList <int>(); for (int i = 1; i <= 10; i++) { list.AddLast(i); } Assert.AreEqual(list.Head.Data, 1); Assert.AreEqual(list.Tail.Data, 10); }
/// <summary> /// Удаление элемента /// </summary> /// <param name="doublyList"></param> private void Delete(ref DoublyList <int> doublyList) { Console.WriteLine("Какой элемент нужно удалить?"); var answer = GetAnswer(); if (answer == null) { return; } doublyList.Remove(answer.Value); }
public void GetDataLastTest() { DoublyList <int> list = new DoublyList <int>(); for (int i = 1; i <= 5; i++) { list.AddLast(i); } Assert.AreEqual(list.GetDataLast(4), 1); Assert.Catch <IndexOutOfRangeException>(() => list.GetDataLast(10)); Assert.Pass(); }
public void FindLastTest() { DoublyList <int> list = new DoublyList <int>(); for (int i = 1; i <= 5; i++) { list.AddLast(i); } Assert.AreEqual(list.FindLast(5), 0); Assert.AreEqual(list.FindLast(6), -1); Assert.Pass(); }
public void RemoveTest() { DoublyList <int> list = new DoublyList <int>(); list.Remove(5); for (int i = 1; i <= 5; i++) { list.AddLast(i); } list.Remove(3); list.Remove(6); Assert.AreEqual(list.Head.Next.Next.Data, 4); Assert.Pass(); }
public void RemoveLastTest() { DoublyList <int> list = new DoublyList <int>(); list.RemoveLast(); for (int i = 1; i <= 5; i++) { list.AddLast(i); } list.RemoveLast(); Assert.AreEqual(list.Tail.Data, 4); Assert.Pass(); }
/// <summary> /// Найти элементы в обраном порядке /// </summary> /// <param name="doublyList"></param> private void ReverseFindInDoublyList(DoublyList <int> doublyList) { Console.WriteLine("Какой элемент нужно найти?"); var answer = GetAnswer(); if (answer == null) { return; } IReadOnlyList <int> result = doublyList .FindReverse(answer.Value) .Select(item => item.Data) .ToList(); Console.Write("Найденные элементы: "); WriteList(result); }
/// <summary> /// Добавить до /// </summary> /// <param name="doublyList"></param> private void AddBefore(ref DoublyList <int> doublyList) { Console.WriteLine("До какого элемента нужно добавить?"); var answer = GetAnswer(); if (answer == null) { return; } Console.WriteLine("Какой элемент добавить?"); var value = GetAnswer(); if (value == null) { return; } doublyList.AddBefore(value.Value, answer.Value); }