public void AddFirstOnEmptyList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddFirst("foo"); string[] expected = new string[] { "foo" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void AddFirstOnLongerList() { SinglyLinkedList list = new SinglyLinkedList(); list.AddLast("foo"); list.AddLast("bar"); list.AddFirst("grille"); var expected = new string[] { "grille", "foo", "bar" }; CollectionAssert.AreEqual(expected, list.ToArray()); }
public void AddFirst(string value) { //if this is the first node, this is just an assignment if (this.First() == null) { first_node = new SinglyLinkedListNode(value); } else { //create a placeholder list to store the values in order. var placeholderList = new SinglyLinkedList(); placeholderList.AddFirst(value); for (var i = 0; i < this.Count(); i++) { placeholderList.AddLast(this.ElementAt(i)); } //now reassign the values to the current linked list in order (this.First() etc) first_node = new SinglyLinkedListNode(placeholderList.First()); for (var q = 1; q < placeholderList.Count(); q++) { this.AddLast(placeholderList.ElementAt(q)); } } }
public void AddFirst(string value) { //if this is the first node, this is just an assignment if (this.First() == null) { first_node = new SinglyLinkedListNode(value); } else { //create a placeholder list to store the values in order. var placeholderList = new SinglyLinkedList(); placeholderList.AddFirst(value); for (var i = 0; i < this.Count(); i++) { placeholderList.AddLast(this.ElementAt(i)); } //now reassign the values to the current linked list in order (this.First() etc) first_node = new SinglyLinkedListNode(placeholderList.First()); for (var q = 1; q < placeholderList.Count(); q++ ) { this.AddLast(placeholderList.ElementAt(q)); } } }
public void testIndexOfNodeInFirst() { SinglyLinkedList list = new SinglyLinkedList(); list.AddFirst("node1"); Assert.AreEqual(0, list.IndexOf("node1")); }
public void testIndexOfNodeForMultipleItems() { SinglyLinkedList list = new SinglyLinkedList(); list.AddFirst("node1"); list.AddLast("node2"); Assert.AreEqual(1, list.IndexOf("node2")); }
public void AddFirst(string value) { if (this.First() == null) { first_node = new SinglyLinkedListNode(value); } else { var newFirstNode = new SinglyLinkedListNode(value); var placeHolderList = new SinglyLinkedList(); placeHolderList.AddFirst(newFirstNode.Value); for (var i = 0; i < this.Count(); i++) { placeHolderList.AddLast(this.ElementAt(i)); } first_node = new SinglyLinkedListNode(placeHolderList.First()); for (var q = 1; q < placeHolderList.Count(); q++) { this.AddLast(placeHolderList.ElementAt(q)); } } }