Question: Create a class LinkedList and add following functions. All function should run in O(n) Write a function Insert that takes two arguments x and j.
- Create a class LinkedList and add following functions. All function should run in O(n)
- Write a function Insert that takes two arguments x and j. Where x and j are integers. The function should insert value x at position j in the linked list.
- Write a function SearchByValue that takes an argument x. Where x is an integer. The function should search the position of the value x in the list and should return the position of the location. It should return -1 if the value is not found.
- Write a function DeleteDuplicates that deletes duplicate values from the linked list.The function should return a sorted list after deleting the duplicate values.
class Node:
def __init__(self,value):
self.value = value
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
def Insert(self,x,j):
// your code goes here
def SearchByValue(self,x):
// your code goes here
def DeleteDuplicates(self):
// your code goes here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
