Foundation·Concept·2 min read

Linked list in C#

Practice this question

Node structure

csharp
public class ListNode {
    public int val;
    public ListNode next;
    public ListNode(int val = 0, ListNode next = null) {
        this.val = val;
        this.next = next;
    }
}

Problems to practice

  • Reverse Linked List
  • Remove Nth Node from End
  • Merge Two Sorted Lists
  • Detect Cycle
  • Middle of the Linked List
  • Intersection of Two Linked Lists

Example: reverse list

csharp
public ListNode ReverseList(ListNode head) {
    ListNode prev = null;
    ListNode curr = head;

    while (curr != null) {
        ListNode next = curr.next;
        curr.next = prev;
        prev = curr;
        curr = next;
    }

    return prev;
}

Adapted from 17_DSA_DOTNET.md · “4. Linked list in C#”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.