Python Practice Queue Linked List

In this class, we make Python Practice Queue Linked List.

For Complete YouTube Video: Click Here

Queue Example

The reader should have basics on Data Structures and python.

For Data structure, please check our Data structures course.

For python, click here.

All these examples will help you improve your coding skill and easily crack the placement exams.

# What will be returned by the following function check_num when the number passed is 125?
Queue class is provided with methods required

def check_num(number):
    queue=Queue(5)
    outpu=0
    out_queue=Queue(5)
    Out_queue.enque(1)
    while(number>0):
        queue.enque(number%10)#enque method will insert element in the queue
        number//10
    while(not queue.isempty()):
        val=queue.deque()
        output=output+(val*val)
        num=out_queue.deque()
        if output%2==0:
            out_queue.enque(output+num)
        else:
            out_queue.enque(val+num)
    return out_queue

Output:
38

In the above program, a queue class is provided, and the methods are written.

The description of methods is provided in the program.

Intuition on how data structures are implemented in python is provided here.

Step by step explanation of the program is given in the video.

Linked List Example

consider the below input_linked_list
input_linked_list(Head to Tail): 'p'->1->'L'->2

What will be the content of input_linked_list
after executing the below function
if input_linked_list and str1='P' are passed as parameters


def modifylinkedlist(input_linked_list,str1):
    temp=input_linked_list.gethead() #gethead() will return head node
    while(temp.getnext().getnext()!=None): #getnext() return next node
        if str1 in temp.getnext().getdata(): #getdata return the data in node
            input_linked_list.add(temp.getdata()) # add will add node at end
            temp=temp.getnext()
        elif (temp.getdata(isdigit())):
            input_linked_list.add(temp.getdata())
        temp=temp.getnext()
    return input_linked_list()

Output:
'P'->1->'L'->2->1

In the above program linked list object is given as input to the function.

We can use the methods available on the linked list and other classes mentioned in the program.

Description About methods is provided in the program.

A complete explanation is provided in the video.