Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions DataStructures.Tests/LinkedList/CircularLinkedListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,20 @@ private static string GetDisplayOutput<T>(CircularLinkedList<T> list)

return result.ToString().Trim();
}

[Test]
public static void InsertAfter_InsertingAfterTail_UpdatesTailAndPreservesHead()
{
var list = new CircularLinkedList<int>();
list.InsertAtEnd(10);

list.InsertAfter(10, 20);

var head = list.GetHead();
Assert.That(head, Is.Not.Null);
Assert.That(head!.Data, Is.EqualTo(10));
Assert.That(head.Next, Is.Not.Null);
Assert.That(head.Next!.Data, Is.EqualTo(20));
Assert.That(head.Next.Next, Is.SameAs(head));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public void InsertAfter(T value, T data)
newNode.Next = current.Next;
current.Next = newNode;

if (tail! == current)
{
tail = newNode;
}

return;
}

Expand Down
Loading