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
Empty file added DSA/Linked-List/__init__.py
Empty file.
62 changes: 0 additions & 62 deletions DSA/Linked-List/linked_list.py

This file was deleted.

61 changes: 0 additions & 61 deletions DSA/Linked-List/merge_two_list.py

This file was deleted.

60 changes: 0 additions & 60 deletions DSA/Linked-List/node.py

This file was deleted.

21 changes: 0 additions & 21 deletions DSA/Linked-List/remove_duplicate_from_sorted_list.py

This file was deleted.

37 changes: 37 additions & 0 deletions DSA/Linked-List/reverse_linkedlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Node:
def __init__(self, val):
self.val = val
self.next = None


a = Node("a")
b = Node("b")
c = Node("c")
d = Node("d")

a.next = b
b.next = c
c.next = d

Comment on lines +7 to +15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Guard the sample execution behind __main__.

Importing this module currently builds data, reverses it, and prints output immediately. That makes reverse_list and print_linked_list awkward to reuse from tests or other modules.

Suggested fix
-a = Node("a")
-b = Node("b")
-c = Node("c")
-d = Node("d")
-
-a.next = b
-b.next = c
-c.next = d
+if __name__ == "__main__":
+    a = Node("a")
+    b = Node("b")
+    c = Node("c")
+    d = Node("d")
+
+    a.next = b
+    b.next = c
+    c.next = d
 ...
-current = reverse_list(a)
-print_linked_list(current)
+    current = reverse_list(a)
+    print_linked_list(current)

Also applies to: 36-37

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@DSA/Linked-List/reverse_linkedlist.py` around lines 7 - 15, The module is
executing sample setup and output at import time instead of only when run
directly. Move the linked-list construction, reversal, and printing that
currently sits alongside reverse_list and print_linked_list into a __main__
guard so importing reverse_linkedlist only exposes the reusable
functions/classes without side effects.


def reverse_list(head):
prev = None
current = head
while current is not None:
next_node = current.next
current.next = prev
prev = current
current = next_node

return prev


def print_linked_list(head):
current = head
while current is not None:
print(current.val)
current = current.next


current = reverse_list(a)
print_linked_list(current)
Loading