In python.....Create a Linked List program using at least 15 items. Must use the following in your program: Min() Max() Index() Count() Remove() Note: Use the "print" statement after each method.
# I have covered all the functions below is the linke to the code
# LINK == > https://repl.it/@FAYAZPASHA/Python-3-6
#code
import math class Node: # Function to initialise the node object def __init__(self, data): self.data = data # Assign data self.next = None # Initialize next as null # Linked List class contains a Node object class LinkedList: # Function to initialize head def __init__(self): self.head = None # Functio to insert a new node at the beginning def push(self, new_data): new_node = Node(new_data) new_node.next = self.head self.head = new_node def printList(self): temp = self.head while (temp): print(temp.data) temp = temp.next # Utility function to print the linked list def allFunctions(self): temp = self.head mn = math.inf mx = 0 while (temp): mn = min(temp.data, mn) mx = max(temp.data, mx) temp = temp.next print("MAX() The MAXIMUM element in the linked list is : ", mx) print() print("MIN() The MINIMUM element in the linked list is : ", mn) def printList(self): temp = self.head while (temp): print(temp.data) temp = temp.next # Press the green button in the gutter to run the script. if __name__ == '__main__': llist = LinkedList() items = [10, 55, 22, 31, 41, 12, 1, 77, 9, 8, 19, 17, 22, 13, 67] for item in items: llist.push(item) # llist.printList() llist.allFunctions() itemLists = ['apple', 'cat', 'ball', 'car', 'car', 'mat', 'car', 'roap', 'stairs', 'cat', 'ball', 'ball', 'mouse', 'mouse', 'computer'] print('INDEX() The index of item [STAIRS] is', itemLists.index('stairs')) print() print('COUNT() count of item [CAR] is ', itemLists.count('car')) print() print() print('REMOVE() The items before using the remove methods') print(itemLists, end=' ') print() print() print('REMOVE() The items after using the remove methods') itemLists.remove('apple') print(itemLists)
Get Answers For Free
Most questions answered within 1 hours.