Python Practice Linked List1

In this class, We do Python Practice Linked List1.

For Complete YouTube Video: Click Here

Linked List Examples

The reader should have prior knowledge of Data Structures and Python. Take our Data Structures Course. For python, Click here.

The examples given will help the reader improve coding skills and easily crack the placement exams.

Q1) The following function takes linked list in_list head as input
It modifies the list by moving the last element to the front of the list
and return the modified list

some part of the code is missing 
Fill the missing part

The methods used on list object are available

def move_to_front(head):
    if (head==None or head.getnext()==None):
        return head
    q=None
    p=head
    while(p.getnext()!=None):
        q=p
        p=p.getnext()
    -----
    -----
    -----
    return head

a) q=None
   p.next=head
   head=p

b) q.next=None
   head=p
   p.next=q

c) head=p
   p.next=q
   q.next=None

d) q.next=None
   p.next=head
   head=p

The function Move_to_front is changing the last node in the in_list to the beginning.

In the code, three lines are given for three program statements.

Identify the correct option to full fill the requirement.

Analyze the code and choose the option for better practice. The logic is explained in the video.

Q2) What will the elements present in the in_list after 
executing the below function
The function take head node of in_list as input

in_list:8->9->7->6->2->1->0

List methods are available for in_list

def func(head):
    while(head.getnext()!=None):
        temp=head.data
        head.data=head.getnext().data
        head.getnext().data=temp
        if head.getnext.next==None:
            head=head.getnext()
        else:
            head=head.getnext().next
    

In the above program, a list object is given. And the function func is taking the head of the in_list as a parameter.

The elements in the list after executing the function func.

Analyze the code for better practice.

A detailed explanation is given in the video.