Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define a function that takes the head of a doubly linked list and an integer Ind as arguments and deletes the node at index Ind.
Define a function that takes the head of a doubly linked list and an integer Ind as arguments and deletes the node at index Ind. The index starts from 1 . The program then prints the modified list. The definition of the linked list has already been given to you. Suppose the given linked list is 5>7>6 and Ind =1, then the modified list will be 76 klass Node: def__init_(self, data): self.data = data self.next = None self.tail=None class LinkedList: def__init_(self): self.head = None def push(self, new_data): new_node = Node (new_data) if self. head==None: self. head=new_node self.tail=new_node else : self.tail. next=new_node self.tail=new_node def deleteNode(self, Ind): \#write your code here def printlist(self): temp = self. head while (temp): print(temp.data, end =" ") temp = temp.next list = LinkedList () = int (input()) x= input () def push(self, new_data): new_node = Node ( new_data ) if self. head==None : self.head=new_node self.tail=new_node else : self,tail,next=new_node self.tail=new_node def deleteNode(self, Ind): \#write your code here def printlist(self): temp = self. head while (temp): print (temp.data, end =" ") temp = temp.next llist = LinkedList () n=int(input()) x= input () if n==len(xsplit()) : for i in x.split() : llist.push(int(i)) key = int(input()) llist.deleteNode(key) list.printList()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started