class Node: def __init__(self, data): self.data = data self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node return current = self.head while current.next: current = current.next current.next = new_node new_node.prev = current def insert(self, index, data): new_node = Node(data) if index == 0: new_node.next = self.head if self.head: self.head.prev = new_node self.head = new_node return current = self.head for _ in range(index - 1): if not current: raise IndexError("Index out of bounds") current = current.next if not current: raise IndexError("Index out of bounds") new_node.next = current.next new_node.prev = current if current.next: current.next.prev = new_node current.next = new_node def delete(self, data): current = self.head while current: if current.data == data: if current.prev: current.prev.next = current.next else: self.head = current.next if current.next: current.next.prev = current.prev return current = current.next raise ValueError(f"{data} not found in list") def reverse(self): current = self.head prev_node = None while current: next_node = current.next current.next = prev_node current.prev = next_node prev_node = current current = next_node self.head = prev_node def find(self, data): current = self.head index = 0 while current: if current.data == data: return index current = current.next index += 1 return -1 def to_list(self): result = [] current = self.head while current: result.append(current.data) current = current.next return result def display_forward(self): current = self.head while current: print(current.data, end=" ⇄ ") current = current.next print("None") def display_backward(self): current = self.head if not current: print("None") return while current.next: current = current.next while current: print(current.data, end=" ⇄ ") current = current.prev print("None") dll = DoublyLinkedList() dll.append(10) dll.append(20) dll.append(30) dll.insert(1, 15) # Insert 15 at index 1 dll.delete(20) # Remove node with value 20 dll.reverse() # Reverse the list print("Index of 15:", dll.find(15)) dll.append(50) print(dll.to_list()) # Output: [30, 15, 10, 50] dll.display_forward() # Output: 30 ⇄ 15 ⇄ 10 ⇄ None dll.display_backward() # Output: 10 ⇄ 15 ⇄ 30 ⇄ None