0
0
DSA Pythonprogramming~10 mins

Doubly Linked List Structure and Node Design in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the Node class with a pointer to the next node.

DSA Python
class Node:
    def __init__(self, data):
        self.data = data
        self.next = [1]
        self.prev = None
Drag options to blanks, or click blank then click option'
ANone
Bself
C0
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to 0 or data instead of None.
Confusing next with prev pointer.
2fill in blank
medium

Complete the code to initialize the previous pointer in the Node class.

DSA Python
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = [1]
Drag options to blanks, or click blank then click option'
A0
Bself
Cdata
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev to 0 or data instead of None.
Confusing prev with next pointer.
3fill in blank
hard

Fix the error in the DoublyLinkedList class constructor to initialize the head pointer.

DSA Python
class DoublyLinkedList:
    def __init__(self):
        self.head = [1]
Drag options to blanks, or click blank then click option'
A0
BNone
Cself
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to 0 or Node instead of None.
Assigning head to self which is incorrect.
4fill in blank
hard

Fill both blanks to complete the method that adds a new node at the beginning of the doubly linked list.

DSA Python
def add_at_beginning(self, data):
    new_node = Node(data)
    new_node.next = [1]
    if self.head is not None:
        self.head.prev = [2]
    self.head = new_node
Drag options to blanks, or click blank then click option'
Aself.head
Bnew_node
Cdata
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping new_node and self.head in assignments.
Forgetting to update the prev pointer of the old head.
5fill in blank
hard

Fill all three blanks to complete the method that prints the doubly linked list from head to tail.

DSA Python
def print_list(self):
    current = self.head
    while current is not [1]:
        print(current.[2], end=' <-> ')
        current = current.[3]
    print('None')
Drag options to blanks, or click blank then click option'
ANone
Bdata
Cnext
Dprev
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next to move forward.
Checking for current == 0 instead of None.