Question: appendix for this question i hv made a mistake, the last one should be this 3. Part C, A1C (10 marks) Write a Python program,
appendix for this question
i hv made a mistake, the last one should be this
3. Part C, A1C (10 marks) Write a Python program, with the given Python files. 0 Doubly-Linked List (DLL): Implement a Doubly-Linked List o Students have learnt conventional (Singly-) Linked-List in our course. In this part, students should implement a simple-version of Doubly-Linked List: Each node in this Doubly-Linked List has two links: one for the next node as in singly- linked list, 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 Doubly-Linked List, which require tracing backward (the previous node of the current node), Students should reuse and modify the given codes of (Singly-) Linked-List in our course. head tail O00-000-000-000 File Aonec.py, to be modified and completed by student. o Include a given class of nodes with a value and two links (to previous and next nodes): # Aonec.py, for IDSA Assign 1 class DLNode: # modelling a node with doubly-linked def __init__(self, invalue=None, inPrev=None, inNext=None): # constructor self.value = invalue # the node data value, default None self.prevN = inPrev # the previous node, default None self.nextn = inNext #the next node, default None class DLList: # defining a class of Doubly-Linked List def __init__(self): # constructor self.headN = None # the head Node self.tailN = None # the tail Node # MORE TO BE MODIFIED AND FINISHED o Extra Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (DLL) Description _init__(): Create and initiate a new DLL (constructor, GIVEN) insertAsTail(elt): Insert element elt as a new tail (GIVEN) displayDL(): Traverse & display node values, in forward order (GIVEN) insertBefore(refelt, elt): Insert element elt, before a reference refelt 4/4 self.value invalue on the node data value, de fault None Include a given class of nodes with a value and two links to previous and next nodes): # Aonec.py, for IDSA Assign 1 DLNode: # modelling a node with doubly-linked _init__(self, invalue=None, inPrev=None, inNext=None): # constructor 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): # constructor self.headN = None # the head Node self.tailN = None # the tail Node # MORE TO BE MODIFIED AND FINISHED O Extra Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (DLL) Description _init__(): Create and initiate a new DLL (constructor, GIVEN) insertAsTail(elt): Insert element elt as a new tail (GIVEN) displayDL(): Traverse & display node values, in forward order (GIVEN) insertBefore(refelt, elt): Insert clement elt, before a reference refelt Do not insert if refelt not existing insertAfter(refelt, elt): Insert element elt, after a reference refelt Do not insert if refelt not existing displayDlBackw(): Traverse & display node values, in backward order O O O Given Materials: Python file Aonec.py, to be modified and completed by student. Also modify top comments for your STUDENT INFO. (DO NOT modify this given portions, including given methods if any) O Python file AoneCT.py for basic running and testing. I DO NOT modify this given test file, except the STUDENT INFO part. Sample console display output of executing the main testing program AoneCT.py --- A1C, DLList program, by --- --- 1. New DLL created -- >>> DOUBLY-Linked-List Display: > ... AN EMPTY LIST --- 2. Insert some items --- >>> DOUBLY-Linked-List Display: > ... head , tail 99): > 11 > 22 > 33 > 55 > 77 > 99 --- 3. insertAfter(55,66) --- >>> DOUBLY-Linked-List Display: > ... head , tail 99): 11 > 22 > 33 > 55 > 66 > 77 > 99 ... 4. insertBefore(55,44) -.. >>> DOUBLY-Linked-List Display: > ... head , tail : > 11 > 22 > 33 > 44 > 55 > 66 > 77 > 99 --- 5. insertAfter(77,88) --- >>> DOUBLY-Linked-List Display: > ... head , tail 99>: 11 > 22 > 33 > 44 > 55 > 66 > 77 > 88 > 99 >>> DOUBLY-Linked-List Display, Backwards: > FROM ... tail , , class DLNode: # modelling a node with doubly-linked def _init__(self, invalue=None, in Prev=None, inNext=None): # constructor self.value = inValue # the node data value, default None self.prevN = in Prev # the previous node, default None self.nextN = 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 Node self.tailN = None # the tail Node def insertAsTail(self, inValue): # GIVEN: insert a new node value, as the new tail if self.headN==None: # case of empty DLL new TailN = DL Node (inValue) # create new Node self.headN = newTailN #link new (Tail) Node self.tailN = self.headN else: newTailN = DLNode (inValue, self.tailN) # create a new (Tail) Node, set its previous node as the current Tail self.tailN.nextN = newTailN # current Tail, links next node as new (Tail) Node self.tailN = new TailN # update Tail Node to the new one def displayDL (self): # GIVEN: traverse & display node values, in forward order print(f">>> DOUBLY-Linked-List Display: >") if self.headN==None: # case of empty list print(" ... AN EMPTY LIST"); return else: # show head value and tail value of list print(f" head ," f" tail :") curN = self.headN while curN!= None: # show data values in the whole list print(f" > {curN.value}", end=") curN = curN.nextN print() if self.headN==None: # case of empty DLL new TailN = DLNode (inValue) # create new Node self.headN = new TailN # link new (Tail) Node self.tailN = self.headN else: newTailN = DLNode(inValue, self.tailN) # create a new (Tail) Node, set its previous node as the current Tail self.tailN.nextN = newTailN # current Tail, links next node as new (Tail) Node self.tailN = newTailN # update Tail Node to the new one def displayDL(self): # GIVEN: traverse & display node values, in forward order print(f">>> DOUBLY-Linked-List Display: >") if self.headN==None: # case of empty list print(" AN EMPTY LIST"); return else: # show head value and tail value of list print(f" head ," f" tail :") curN = self.headN while curN!= None: # show data values in the whole list print(f" > {curN.value}", end=") curN = curN.nextN print() ######### ######## STUDNET'S WORK ###################### # simple comment HERE def insertBefore(self, refValue, WV): # insert a new node, BEFORE the ref Node (value) pass # TO BE MODIFIED AND COMPLETED # simple comment HERE def insertAfter(self, refValue, newV): # insert a new node, AFTER the ref Node (value) pass # TO BE MODIFIED AND COMPLETED # simple comment HERE def displayDLBackw(self): print(f">>> DOUBLY-Linked-List Display, Backwards: >") pass # TO BE MODIFIED AND COMPLETED # AoneCT.py, for basic running and testing. #* DO NOT modify this given test file, except the STUDENT INFO part. # Main Testing Program from AoneB import AList === def main(): print("= A1B, Enhanced ArrayList, by === ") myL = AList() print(f"--- 1. New AL created, isEmptyL() result: {myL.isEmptyL()}") myL.insertL('A', 1); myL.insertL('C', 2); myL.appendL('ABC'); myL.appendL('D'); myL.appendL('B'); print(" --- 2. Finished AppendL(): A,C > ABC,D,B ---") myL.displayL() print(f" removeLastL(), elt is {myL.removeLastL()}") print(" --- 3. Finished removeLastL ---") myL.displayL() print(f" --- 4. isEmptyL(), value: {myL.isEmptyL()}") print(f" --- 5. searchL('ABC'), pos value: {myL.searchL('ABC')}") print(f" --- 6. searchL('XYZ'), pos value: {myL.searchL('XYZ')}") print(" === Program ends === ") main() File Edit Format Run Options Window Help AoneCT.py for basic running and testing. # DO NOT modify this given test file, except the STUDENT INFO part. # Main Testing Program from Aonec impor: DLList def main(): print(" = A10, DLList program by = myL = DLList print(" -- 1. New DL created ---") myl.displayDLO myl.insertAsTail(11); myll.insertAsTail (22); myl. insertasTail(33) myL. insertasTail(55): nyl.insertAsTail(77); myl. insertasTail(99) print( \0--- 2. Insert some items --- myl.displayDLO myl.insertAfter(55,66) myL.insertAfter(555,666) print(" 1--- 3. insertAfACT (5.66 --- myL.displayDLO myL.insertBefore(55.44) myL.insertBefore(5.4) print(" --- 4 insertBefore(6544 myl.displayDLO myl.insertAfter 77.88) print("n--- 5 Laserta ber38 myl.displayDLO myl displayDLBacky() print 1 Program ands ==) main 3. Part C, A1C (10 marks) Write a Python program, with the given Python files. 0 Doubly-Linked List (DLL): Implement a Doubly-Linked List o Students have learnt conventional (Singly-) Linked-List in our course. In this part, students should implement a simple-version of Doubly-Linked List: Each node in this Doubly-Linked List has two links: one for the next node as in singly- linked list, 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 Doubly-Linked List, which require tracing backward (the previous node of the current node), Students should reuse and modify the given codes of (Singly-) Linked-List in our course. head tail O00-000-000-000 File Aonec.py, to be modified and completed by student. o Include a given class of nodes with a value and two links (to previous and next nodes): # Aonec.py, for IDSA Assign 1 class DLNode: # modelling a node with doubly-linked def __init__(self, invalue=None, inPrev=None, inNext=None): # constructor self.value = invalue # the node data value, default None self.prevN = inPrev # the previous node, default None self.nextn = inNext #the next node, default None class DLList: # defining a class of Doubly-Linked List def __init__(self): # constructor self.headN = None # the head Node self.tailN = None # the tail Node # MORE TO BE MODIFIED AND FINISHED o Extra Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (DLL) Description _init__(): Create and initiate a new DLL (constructor, GIVEN) insertAsTail(elt): Insert element elt as a new tail (GIVEN) displayDL(): Traverse & display node values, in forward order (GIVEN) insertBefore(refelt, elt): Insert element elt, before a reference refelt 4/4 self.value invalue on the node data value, de fault None Include a given class of nodes with a value and two links to previous and next nodes): # Aonec.py, for IDSA Assign 1 DLNode: # modelling a node with doubly-linked _init__(self, invalue=None, inPrev=None, inNext=None): # constructor 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): # constructor self.headN = None # the head Node self.tailN = None # the tail Node # MORE TO BE MODIFIED AND FINISHED O Extra Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (DLL) Description _init__(): Create and initiate a new DLL (constructor, GIVEN) insertAsTail(elt): Insert element elt as a new tail (GIVEN) displayDL(): Traverse & display node values, in forward order (GIVEN) insertBefore(refelt, elt): Insert clement elt, before a reference refelt Do not insert if refelt not existing insertAfter(refelt, elt): Insert element elt, after a reference refelt Do not insert if refelt not existing displayDlBackw(): Traverse & display node values, in backward order O O O Given Materials: Python file Aonec.py, to be modified and completed by student. Also modify top comments for your STUDENT INFO. (DO NOT modify this given portions, including given methods if any) O Python file AoneCT.py for basic running and testing. I DO NOT modify this given test file, except the STUDENT INFO part. Sample console display output of executing the main testing program AoneCT.py --- A1C, DLList program, by --- --- 1. New DLL created -- >>> DOUBLY-Linked-List Display: > ... AN EMPTY LIST --- 2. Insert some items --- >>> DOUBLY-Linked-List Display: > ... head , tail 99): > 11 > 22 > 33 > 55 > 77 > 99 --- 3. insertAfter(55,66) --- >>> DOUBLY-Linked-List Display: > ... head , tail 99): 11 > 22 > 33 > 55 > 66 > 77 > 99 ... 4. insertBefore(55,44) -.. >>> DOUBLY-Linked-List Display: > ... head , tail : > 11 > 22 > 33 > 44 > 55 > 66 > 77 > 99 --- 5. insertAfter(77,88) --- >>> DOUBLY-Linked-List Display: > ... head , tail 99>: 11 > 22 > 33 > 44 > 55 > 66 > 77 > 88 > 99 >>> DOUBLY-Linked-List Display, Backwards: > FROM ... tail , , class DLNode: # modelling a node with doubly-linked def _init__(self, invalue=None, in Prev=None, inNext=None): # constructor self.value = inValue # the node data value, default None self.prevN = in Prev # the previous node, default None self.nextN = 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 Node self.tailN = None # the tail Node def insertAsTail(self, inValue): # GIVEN: insert a new node value, as the new tail if self.headN==None: # case of empty DLL new TailN = DL Node (inValue) # create new Node self.headN = newTailN #link new (Tail) Node self.tailN = self.headN else: newTailN = DLNode (inValue, self.tailN) # create a new (Tail) Node, set its previous node as the current Tail self.tailN.nextN = newTailN # current Tail, links next node as new (Tail) Node self.tailN = new TailN # update Tail Node to the new one def displayDL (self): # GIVEN: traverse & display node values, in forward order print(f">>> DOUBLY-Linked-List Display: >") if self.headN==None: # case of empty list print(" ... AN EMPTY LIST"); return else: # show head value and tail value of list print(f" head ," f" tail :") curN = self.headN while curN!= None: # show data values in the whole list print(f" > {curN.value}", end=") curN = curN.nextN print() if self.headN==None: # case of empty DLL new TailN = DLNode (inValue) # create new Node self.headN = new TailN # link new (Tail) Node self.tailN = self.headN else: newTailN = DLNode(inValue, self.tailN) # create a new (Tail) Node, set its previous node as the current Tail self.tailN.nextN = newTailN # current Tail, links next node as new (Tail) Node self.tailN = newTailN # update Tail Node to the new one def displayDL(self): # GIVEN: traverse & display node values, in forward order print(f">>> DOUBLY-Linked-List Display: >") if self.headN==None: # case of empty list print(" AN EMPTY LIST"); return else: # show head value and tail value of list print(f" head ," f" tail :") curN = self.headN while curN!= None: # show data values in the whole list print(f" > {curN.value}", end=") curN = curN.nextN print() ######### ######## STUDNET'S WORK ###################### # simple comment HERE def insertBefore(self, refValue, WV): # insert a new node, BEFORE the ref Node (value) pass # TO BE MODIFIED AND COMPLETED # simple comment HERE def insertAfter(self, refValue, newV): # insert a new node, AFTER the ref Node (value) pass # TO BE MODIFIED AND COMPLETED # simple comment HERE def displayDLBackw(self): print(f">>> DOUBLY-Linked-List Display, Backwards: >") pass # TO BE MODIFIED AND COMPLETED # AoneCT.py, for basic running and testing. #* DO NOT modify this given test file, except the STUDENT INFO part. # Main Testing Program from AoneB import AList === def main(): print("= A1B, Enhanced ArrayList, by === ") myL = AList() print(f"--- 1. New AL created, isEmptyL() result: {myL.isEmptyL()}") myL.insertL('A', 1); myL.insertL('C', 2); myL.appendL('ABC'); myL.appendL('D'); myL.appendL('B'); print(" --- 2. Finished AppendL(): A,C > ABC,D,B ---") myL.displayL() print(f" removeLastL(), elt is {myL.removeLastL()}") print(" --- 3. Finished removeLastL ---") myL.displayL() print(f" --- 4. isEmptyL(), value: {myL.isEmptyL()}") print(f" --- 5. searchL('ABC'), pos value: {myL.searchL('ABC')}") print(f" --- 6. searchL('XYZ'), pos value: {myL.searchL('XYZ')}") print(" === Program ends === ") main() File Edit Format Run Options Window Help AoneCT.py for basic running and testing. # DO NOT modify this given test file, except the STUDENT INFO part. # Main Testing Program from Aonec impor: DLList def main(): print(" = A10, DLList program by = myL = DLList print(" -- 1. New DL created ---") myl.displayDLO myl.insertAsTail(11); myll.insertAsTail (22); myl. insertasTail(33) myL. insertasTail(55): nyl.insertAsTail(77); myl. insertasTail(99) print( \0--- 2. Insert some items --- myl.displayDLO myl.insertAfter(55,66) myL.insertAfter(555,666) print(" 1--- 3. insertAfACT (5.66 --- myL.displayDLO myL.insertBefore(55.44) myL.insertBefore(5.4) print(" --- 4 insertBefore(6544 myl.displayDLO myl.insertAfter 77.88) print("n--- 5 Laserta ber38 myl.displayDLO myl displayDLBacky() print 1 Program ands ==) main