public static void Main(string[] args) { MyDoublyLinkedList list = new MyDoublyLinkedList(); list.AddFirst("Hello"); list.AddLast("world"); list.AddLast("!"); list.AddLast("!"); list.AddLast("!"); list.AddLast("!"); list.RemoveByIndex(0); list.AddFirst("Hi"); // check = true var check = list.RemoveEveryEqual("!"); var array = list.ToArray(); // Hi // world foreach (var @object in array) { Console.WriteLine(@object); } list.AddFirst("Bob"); list.AddFirst("Eugene"); list[0] = "Zero"; list.RemoveByIndex(1); list.RemoveFirst(); array = list.ToArray(); // Bob // Hi // world foreach (var @object in array) { Console.WriteLine(@object); } list.Clear(); }
public void Should_Add_First_When_List_Length_Greater_One() { //arrange var node1 = new MyDoublyLinkedListNode <int>(1); var node2 = new MyDoublyLinkedListNode <int>(2); var node3 = new MyDoublyLinkedListNode <int>(3); var node4 = new MyDoublyLinkedListNode <int>(4); node1.Next = node2; node2.Next = node3; node3.Next = node4; node2.Prev = node1; node3.Prev = node2; node4.Prev = node3; var list = new MyDoublyLinkedList <int>(node1); var node5 = new MyDoublyLinkedListNode <int>(5); //act list.AddFirst(node5); //assert list.Count.ShouldBeEquivalentTo(5); list.Head.ShouldBeEquivalentTo(node5); list.Tail.ShouldBeEquivalentTo(node4); list.Head.Next.ShouldBeEquivalentTo(node1); list.Head.Next.Next.ShouldBeEquivalentTo(node2); list.Head.Next.Next.Next.ShouldBeEquivalentTo(node3); list.Head.Next.Next.Next.Next.ShouldBeEquivalentTo(node4); }
public void MyLinkedList_NotEquals_OriginalLinkedList() { LinkedList <int> originalLinkedList = _linkedListService.CreateLinkedList(new LinkedList <int>()) as LinkedList <int>; MyDoublyLinkedList <int> myLinkedList = _linkedListService.CreateLinkedList(new MyDoublyLinkedList <int>()) as MyDoublyLinkedList <int>; ArrangeAndActUponLinkedLists(originalLinkedList, myLinkedList); myLinkedList.AddFirst(1); Assert.NotEqual(myLinkedList, originalLinkedList); }
public void Should_Add_First_Throw_If_Null() { //arrange var list = new MyDoublyLinkedList <int>(); //act Action act = () => list.AddFirst(null); //assert act.ShouldThrow <ArgumentNullException>(); }
public void Should_Add_First_When_List_Is_Empty() { //arrange var list = new MyDoublyLinkedList <int>(); var node = new MyDoublyLinkedListNode <int>(1); //act list.AddFirst(node); //assert list.Count.ShouldBeEquivalentTo(1); list.Head.ShouldBeEquivalentTo(list.Tail); list.Head.ShouldBeEquivalentTo(node); }
public void Enqueue(Animal animal) { if (animal == null) { throw new ArgumentNullException(); } animal.Order = _order++; if (animal is Dog dog) { _dogs.AddFirst(new MyDoublyLinkedListNode <Dog>(dog)); } if (animal is Cat cat) { _cats.AddFirst(new MyDoublyLinkedListNode <Cat>(cat)); } }
private void ArrangeAndActUponLinkedLists(LinkedList <int> originalLinkedList, MyDoublyLinkedList <int> myLinkedList) { LinkedListNode <int> fiveHundredListNode = new LinkedListNode <int>(500); LinkedListNode <int> tenListNode = new LinkedListNode <int>(10); LinkedListNode <int> last = new LinkedListNode <int>(666); MyLinkedListNode <int> myFiveHundredListNode = new MyLinkedListNode <int>(500); MyLinkedListNode <int> myTenListNode = new MyLinkedListNode <int>(10); MyLinkedListNode <int> myLast = new MyLinkedListNode <int>(666); originalLinkedList.AddFirst(tenListNode); originalLinkedList.AddBefore(tenListNode, 9); originalLinkedList.AddAfter(tenListNode, fiveHundredListNode); originalLinkedList.AddLast(last); originalLinkedList.Remove(10); originalLinkedList.AddAfter(last, 777); originalLinkedList.Remove(fiveHundredListNode); originalLinkedList.RemoveFirst(); originalLinkedList.RemoveLast(); originalLinkedList.Clear(); originalLinkedList.AddLast(5); originalLinkedList.RemoveFirst(); myLinkedList.AddFirst(myTenListNode); myLinkedList.AddBefore(myTenListNode, 9); myLinkedList.AddAfter(myTenListNode, myFiveHundredListNode); myLinkedList.AddLast(myLast); myLinkedList.Remove(10); myLinkedList.AddAfter(myLast, 777); myLinkedList.Remove(myFiveHundredListNode); myLinkedList.RemoveFirst(); myLinkedList.RemoveLast(); myLinkedList.Clear(); myLinkedList.AddLast(5); myLinkedList.RemoveFirst(); }