Updated insert method to allow items to be added to the end of the list.
This commit is contained in:
parent
7bb55b8845
commit
1db992492b
@ -105,9 +105,12 @@ namespace C_.Datastructures
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set tail to new item if index is the end
|
//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);
|
Append(value);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fetch point in list and add new item
|
//Fetch point in list and add new item
|
||||||
|
@ -29,14 +29,15 @@ list.Append(3);
|
|||||||
list.Append(4);
|
list.Append(4);
|
||||||
list.Append(5);
|
list.Append(5);
|
||||||
list.Append(6);
|
list.Append(6);
|
||||||
|
list.Insert(6, 1);
|
||||||
|
|
||||||
Console.Write($"{list[0]} ");
|
Console.Write($"{list[0]} ");
|
||||||
Console.Write($"{list[1]} ");
|
Console.Write($"{list[1]} ");
|
||||||
Console.Write($"{list[2]} ");
|
Console.Write($"{list[2]} ");
|
||||||
Console.Write($"{list[3]} ");
|
Console.Write($"{list[3]} ");
|
||||||
Console.Write($"{list[4]} ");
|
Console.Write($"{list[4]} ");
|
||||||
Console.Write($"{list[5]} \n");
|
Console.Write($"{list[5]} ");
|
||||||
Console.Write($"{list[6]} ");
|
Console.Write($"{list[6]} \n");
|
||||||
|
|
||||||
|
|
||||||
//DoublyLinkedList<int> list2 = new DoublyLinkedList<int>();
|
//DoublyLinkedList<int> list2 = new DoublyLinkedList<int>();
|
||||||
|
Loading…
Reference in New Issue
Block a user