Updated insert method to allow items to be added to the end of the list.

This commit is contained in:
Luke Else 2022-03-23 21:20:19 +00:00
parent 7bb55b8845
commit 1db992492b
2 changed files with 7 additions and 3 deletions

View File

@ -105,9 +105,12 @@ namespace C_.Datastructures
}
//Set tail to new item if index is the end
if (index == Count)
if (index == Count - 1)
{
//Decrement count as it will be be re-incremented once appended
Count--;
Append(value);
return;
}
//Fetch point in list and add new item

View File

@ -29,14 +29,15 @@ list.Append(3);
list.Append(4);
list.Append(5);
list.Append(6);
list.Insert(6, 1);
Console.Write($"{list[0]} ");
Console.Write($"{list[1]} ");
Console.Write($"{list[2]} ");
Console.Write($"{list[3]} ");
Console.Write($"{list[4]} ");
Console.Write($"{list[5]} \n");
Console.Write($"{list[6]} ");
Console.Write($"{list[5]} ");
Console.Write($"{list[6]} \n");
//DoublyLinkedList<int> list2 = new DoublyLinkedList<int>();