Complete the code to create a linked list node with a value.
class Node: def __init__(self, data): self.data = data self.[1] = None
The next attribute points to the next node in the linked list.
Complete the code to add a new node at the beginning of the linked list.
def add_at_head(head, data): new_node = Node(data) new_node.[1] = head return new_node
We set the new node's next to the current head to link it properly.
Fix the error in the code to traverse and print all node values in the linked list.
def print_list(head): current = head while current is not None: print(current.data) current = current.[1]
To move forward through the list, update current to current.next.
Complete the code to add a new node at the end of the linked list.
def add_at_tail(head, data): new_node = Node(data) if head is None: return new_node current = head while current.[1] is not None: current = current.next current.[2] = new_node return head
Traverse to the last node using current.next and then link the new node with current.next = new_node.
Complete the code to reverse the linked list iteratively.
def reverse(head): prev = None curr = head while curr is not None: next_temp = curr.[1] curr.[2] = prev prev = curr curr = next_temp return prev
Save curr.next in next_temp before setting curr.next = prev to reverse the direction.
