Question: You are given a single linked list of integer values. Write a function to re-arrange the list such that all odd values should be removed

  1. You are given a single linked list of integer values. Write a function to re-arrange the list such that all odd values should be removed the list without affecting the order of the list. You can use the following classes for your reference. You can add any other functions if required. Your function will be tested using ToList() so make sure that your solution consist this function which is already given.

class Node:

def __init__(self,value):

self.value = value

self.next = None

class LinkedList:

def __init__(self):

self.head = None

self.tail = None

def InsertAtFirst(self, e):

n = Node(e)

n.next = self.head

self.head = n

def ToList(self):

num = []

x = self.head

while (x != None):

num.append(x.value)

x = x.next

return(num)

def ReArrange(self):

// your code goes here

Example:

l = LinkedList()

l.InsertAtFirst(5)

l.InsertAtFirst(4)

l.InsertAtFirst(10)

l.InsertAtFirst(3)

l.ReArrange()

print(l.ToList())

# output

[10, 4]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!