Question: #Code from zyBook 4.6 class LinkedList: def __init__(self): self.head = None self.tail = None def append(self, new_node): if self.head == None: self.head = new_node self.tail
#Code from zyBook 4.6 class LinkedList: def __init__(self): self.head = None self.tail = None def append(self, new_node): if self.head == None: self.head = new_node self.tail = new_node else: self.tail.next = new_node self.tail = new_node def prepend(self, new_node): if self.head == None: self.head = new_node self.tail = new_node else: new_node.next = self.head self.head = new_node def insert_after(self, current_node, new_node): if self.head == None: self.head = new_node self.tail = new_node elif current_node is self.tail: self.tail.next = new_node self.tail = new_node else: new_node.next = current_node.next current_node.next = new_node def remove_after(self, current_node): # Special case, remove head if (current_node == None) and (self.head != None): succeeding_node = self.head.next self.head = succeeding_node if succeeding_node == None: # Remove last item self.tail = None elif current_node.next != None: succeeding_node = current_node.next.next current_node.next = succeeding_node if succeeding_node == None: # Remove tail self.tail = current_node #Let's add a print function def print(self): # Output final list print('List Contents:', end=' ') node = self.head while node != None: print(node.data, end='->') node = node.next print() #We will add a search function 3/8/21 def ListSearch(self,list, key): curNode = list.head while (curNode is not None): if (curNode.data == key): return curNode curNode = curNode.next return None Using linked lists, write a Python program that performs the following tasks: Generate a file named (students.txt) that contains the ID numbers (i.e., nine-digit number beginning with 900) for 100 CAU students. Read the ID numbers generated from this file into a linked list Allow the user to search the linked list - any number of times - for a student's ID number; display a message indicating whether or not the student's ID number was in the linked list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
