Data Structures, Algorithms, Data Engineering, Data Science, Linked Lists.
not curr_1 or not curr_2: return if prev_1: prev_1.next = curr_2 else: self.head = curr_2 if prev_2: prev_2.next = curr_1 else: self.head = curr_1 curr_1.next, curr_2.next = curr_2.next, curr_1.next # Swap llist.swap(1, 5) llist.display() # Output: 5 -> 4 -> 1 -> None 4. Traversal Traversal