Skip to content

Fix tail update on insertion in CircularLinkedList - #583

Merged
siriak merged 2 commits into
TheAlgorithms:masterfrom
mohamedTarek-143:patch-1
Oct 31, 2026
Merged

siriak merged 2 commits into
TheAlgorithms:masterfrom
mohamedTarek-143:patch-1

Conversation

@mohamedTarek-143

Copy link
Copy Markdown
Contributor

Summary of Changes

Fixed a bug in CircularLinkedList.InsertAfter where inserting a node after the current tail failed to update the tail pointer to the newly created node.

Motivation & Context

In a circular linked list tracked by a single tail pointer, the head of the list is defined as tail.Next. When calling InsertAfter(value, data) where value belongs to the current tail, the new node was correctly linked after tail, but tail itself was never reassigned to newNode. Consequently, the list structure became inverted: the newly inserted element was treated as the new head (tail.Next), and the old tail remained marked as the end of the list.

Checklist

[x] I have performed a self-review of my code
[x] My code follows the style guidelines of this project
[x] I have added tests that prove my fix is effective or that my feature works
[x] New and existing unit tests pass locally with my changes
[x] Comments in areas I changed are up to date
[ ] I have added comments to hard-to-understand areas of my code
[ ] I have made corresponding changes to the README.md

@codacy-production

codacy-production Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new test is declared outside the CircularLinkedListTests class at namespace scope, causing C# error CS0116 and preventing the test project from compiling.

1 open issue
What changed in this PR

This PR fixes CircularLinkedList<T>.InsertAfter so inserting after the tail updates the tail pointer and preserves the existing head.

Changes:

  • Reassigns tail to the new node when inserting after the current tail.
  • Adds a regression test checking head preservation, node order, and circular linkage.
File Description
DataStructures/​LinkedList/​CircularLinkedList/​CircularLinkedList.cs Updates the tail pointer after tail insertion.
DataStructures.Tests/​LinkedList/​CircularLinkedListTests.cs Adds a regression test for insertion after a single-node list’s tail.

Review effort: Balanced

@siriak

siriak commented Oct 30, 2026

Copy link
Copy Markdown
Member

Hi, still see the remaining formatting issues
image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the circular-list tail-pointer update and its regression test.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues blocking the tail-insertion fix and its regression coverage.

No open issues 🎉

Review effort: Balanced

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.96%. Comparing base (96e2905) to head (f979a77).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
- Coverage   96.96%   96.96%   -0.01%     
==========================================
  Files         300      300              
  Lines       12598    12602       +4     
  Branches     1842     1843       +1     
==========================================
+ Hits        12216    12219       +3     
  Misses        242      242              
- Partials      140      141       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak
siriak merged commit 6d3b02a into TheAlgorithms:master Oct 31, 2026
3 of 4 checks passed
@mohamedTarek-143

Copy link
Copy Markdown
Contributor Author

You are welcome :)

@mohamedTarek-143
mohamedTarek-143 deleted the patch-1 branch October 31, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants