Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add cycle creation utility and detection tests for Linked List (Fixes #583) #2052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sowmya-rebbavarapu wants to merge 1 commit into trekhleb:master
base: master
Choose a base branch
Loading
from sowmya-rebbavarapu:feat/linked-list-cycle

Conversation

Copy link

@sowmya-rebbavarapu sowmya-rebbavarapu commented May 24, 2025

Description:
This pull request adds the ability to create a cycle in the linked list by linking the tail node to any node at a specified position. It includes:

A utility function createCycle(list, position) that links the last node to the node at the given position to form a cycle.

Unit tests to verify cycle creation and detection using the existing detectCycle function.

Tests cover normal cases, invalid positions, and no-cycle scenarios.

This addresses the feature request in issue #583 opened by @chrisVillanueva, enabling users to create and detect cycles within linked lists for more comprehensive linked list operations.

Please review the implementation and tests. Looking forward to your feedback!

lazarljubenovic reacted with thumbs down emoji
Copy link

That's not a linked list anymore.

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

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

Great job on this test suite! Here are some specific observations and suggestions:

Positives

  • Test Coverage: The tests cover a good range of scenarios, including:
    • No cycle in the linked list
    • Correct cycle creation and detection
    • Handling invalid positions for cycle creation (out-of-bounds and negative)
  • Readability: Test cases are clear and descriptive, making it easy to understand the intention behind each scenario.
  • Setup: Using beforeEach to initialize a new LinkedList keeps tests isolated and reliable.

Suggestions/Improvements

  1. Edge Cases:
    Consider adding tests for these edge cases:

    • An empty list (should return false for cycle detection).
    • A list with a single node (cycle vs. no cycle).
    • Creating a cycle at position 0 (head node).
  2. Assertions:
    If createCycle returns a value (such as success/failure), consider asserting it as well to make the effect of the function explicit.

  3. Comments:
    Your current comments are helpful! If possible, expand them a bit for maintainability, especially in less obvious scenarios.

  4. Consistency:
    The pattern and naming are consistent and align with best practices for unit testing in JavaScript.


lazarljubenovic reacted with thumbs down emoji
Copy link

What a waste of GPU cycles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@Imran-imtiaz48 Imran-imtiaz48 Imran-imtiaz48 left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /