Skip to content

Conversation

ahyalfan
Copy link

@ahyalfan ahyalfan commented Sep 8, 2025

Description of Change

Problem

The original DelByPos function had incorrect position validation and boundary checks, causing errors when deleting nodes at valid positions, especially at the start and end of the list.
Specifically, the conditions used pos-1 inconsistently, leading to off-by-one errors and incorrect calls to deletion methods.

Solution

  • Updated position validation to correctly check if pos is within [1, ll.length].
  • Fixed boundary checks to correctly call DelAtEnd()whenpos == ll.length`.
  • Adjusted the switch cases accordingly to reflect 1-based indexing for positions.
  • Added test cases to cover successful deletions at various positions and to ensure invalid positions return false.

Testing

  • Added new tests for DelByPos() covering success and failure cases.
  • All tests pass.

Checklist

Notes:

Fixed off-by-one errors by properly validating position with 1-based
indexing.
Now DelByPos correctly handles deleting nodes at the beginning, middle,
and end.
Added checks for invalid positions to return false safely.
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.

1 participant