educative.io

Educative

There is the bug in the DoublyLinkedList.py

Challenge 3: Reversing First k Elements of Queue

The issue can be replicated by when you try to print a Q of length =1
queue_obj = MyQueue()
for i in [11]:
queue_obj.enqueue(i)
print(“print_list(): " + queue_obj.display())
Existing Code in Educative.io:
def str(self):
val=”"
if(self.is_empty()):
return “”
else:
temp = self.head
val = “[” + str(temp.data) + ", "
temp = temp.next_element
while (temp.next_element):
val = val + str(temp.data) + ", "
temp = temp.next_element
val = val + str(temp.data) + “]”
return val

This should be updated to the below:

def __str__(self):
    val=""
    if(self.is_empty()):
        return ""
    temp = self.head
    val = "[" + str(temp.data)
    temp = temp.next_element
    if temp!=None:
        while (temp.next_element):
            val = val + ", "+ str(temp.data) 
            temp = temp.next_element
    if temp==None:
        val = val  + "]"
    else:
        val = val + ", "+str(temp.data) + "]"
    return val

=====================