0
0
DSA Pythonprogramming~10 mins

Queue Implementation Using Linked List 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 create a node with given data.

DSA Python
class Node:
    def __init__(self, data):
        self.data = [1]
        self.next = None
Drag options to blanks, or click blank then click option'
Aself
Bnext
CNode
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of 'data' for the node's data.
Assigning 'self' or 'Node' instead of the parameter.
2fill in blank
medium

Complete the enqueue method to add a new node at the end of the queue.

DSA Python
def enqueue(self, data):
    new_node = Node(data)
    if self.rear is None:
        self.front = self.rear = new_node
    else:
        self.rear.next = [1]
        self.rear = new_node
Drag options to blanks, or click blank then click option'
Anew_node
Bself.front
Cself.rear
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning rear.next to self.front or self.rear instead of new_node.
Assigning rear.next to data instead of a node.
3fill in blank
hard

Fix the error in the dequeue method to correctly remove the front node.

DSA Python
def dequeue(self):
    if self.front is None:
        return None
    temp = self.front
    self.front = self.front.[1]
    if self.front is None:
        self.rear = None
    return temp.data
Drag options to blanks, or click blank then click option'
Aprev
Bnext
Cfront
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which does not exist in singly linked list nodes.
Using 'data' or 'front' which are not pointers to the next node.
4fill in blank
hard

Fill both blanks to check if the queue is empty.

DSA Python
def is_empty(self):
    return self.[1] is [2]
Drag options to blanks, or click blank then click option'
Afront
Brear
CNone
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Checking rear instead of front.
Comparing to True instead of None.
5fill in blank
hard

Fill all three blanks to implement a method that prints all elements in the queue.

DSA Python
def display(self):
    current = self.[1]
    while current is not [2]:
        print(current.[3], end=' -> ')
        current = current.next
    print('None')
Drag options to blanks, or click blank then click option'
Afront
BNone
Cdata
Drear
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from rear instead of front.
Checking for True instead of None in the loop condition.
Printing 'next' instead of 'data'.