Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Part C, A1C (10 marks) Write Python program, with the given Python files. D In this part Doubly-Linked List (DLL): Implement Doubly linked List
3. Part C, A1C (10 marks) Write Python program, with the given Python files. D In this part Doubly-Linked List (DLL): Implement Doubly linked List Students have learnt conventional (Singly.) Linked-List in our course. students should implement a simple version of Doubly-Linked List Each node in this Dowbly-Linked Lashes iwo links: one for the next nede as in singly linked lise, the other for the previous node. The head node has no previous link and the tail node has no next link. Some operations could be done for efficiently with this Double Linked I.ex, which rexpire tracing backward (the previous mode of the current node). 0 Students should reise und modify the given codes af (Singly) Linked List in our course head ta Q-0-000-000-00 File Anec. Py to be modified and completed by wwdent. 0 inclue a given clau ofrodes with a value and works to previous and went wer): #Aone.py for TDSA sign 1 class OLNode: modelling a node with doubly-linked def init_(self, invaluerene, inPrevene, inext-None): constructor self.value - invalue the red data value, default None self.prevN = inPrev the previous node, default None self.nextN in Next the next node, default None class oLListi # defining a class of Doubly-Linked List def __init__(self): constructor self.headh - None the head Mode self. tailN - None # the tail Node #MORE TO SE MODIFIED AND FINISHED Extra Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (DLS) Description init(): Create and initiate a new DLL (constructor GIVEN) insertasTail(lt): Insert elementelt as a new tail (GIVEN) displayDL(): Traverse display modo valocs, in forward order (GIVEN) insertBefore(refelt, elt): Insert Ulument elt, before a reference refelt Do not insert if refelt not existing insertAfter(refelt, elt): Insert elementelt, after a reference refelt o Do not insert if refelt not existing displayblback(): Traverse & display bodu values, in backward order del Elass DL Node: # modelling a node with doubly-linked _init__(self, invalue=None, inPrev=llone, inNext None): # constructor self.value = invalue # the node data value, default None self.prevN = inPrev # the previous node, default None self.next = inNext # the next node, default None class DLList: # defining a class of Doubly-Linked List def __init__(self): # GIVEN: constructor self.headN= None # the head Nodo self.tailN = None # the tail Node daf insertAsTail(self, invalue): # GIVEN: insert a new node value, as the new tail if self.headNewNone: #case of empty DLL newTailN - DLNode (inValue) # create new Node self.headN = newTailN # link new (Tail) Node self.tailN = self.headN newTail = DLNode(invalue, self.tailN) # create a new (Tail) Nodo, set its previous node as the current Tail self.tails.next = newtails # current Tail, links next node as now (Tail) Nodo self.tails - nawTailN # update Tail Node to the new one det displayol(self): GIVEN: traverse & display node vplues, in forward order print(">>> DOUBLY-Linked-List Display: >") if self.head more: # case of empty list print AN EMPTY LIST); return niso: # show head value and tail value of list printti head :) CUTN = self.headN while curnt None: show data values in the whole list print(" > (curN.value}", ende) CUIN = curN.nextN print) *WWW STUDNET'S WORK WW########## #simple comment HERE def insertBefore(self, refvalue, newv): # insert a new node, BEFORE the ref Node (value) gass # TO BE MODIFIED AND COMPLETED # simple comment HERE dot insertAfter self. ref Value, new): pass # TO BE MODIFIED AND COMPLETED insert # new node, AFTER the ref Node (value) # simple conment HERE dot display L Backw(self): printf>> DOUBLY-Linked-List Display, Backwards: >") pass TO BE MODIFIED AND COMPLETED
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