Question: #Python Consider an (error-prone) Ordered Linked List implementation with a head reference that only has a constructor and addToFront method defined. In the space below,
#Python
Consider an (error-prone) Ordered Linked List implementation with a head reference that only has a constructor and addToFront method defined. In the space below, write a method isDescending(self) in the orderedLinkedlist class that returns True if the elements in the Ordered Linked List are in descending order (greatest to least from the head reference to the end of the Linked List), and returns False otherwise. You may assume that the data in the Linked List support the operators with each other, and all data in the Ordered Linked List are unique (no duplicates). An edge case to consider (and is shown in the test cases below) is: An Ordered Linked List with no elements or only one element is considered in descending order, and will return True in these cases. The Ordered LinkedList implementation is defined below: class Node: definit__(self, data): self.data = data self.next = None def getData(self): return self.data def getNext(self): return self.next def setData(self, newData): self.data = newData def setNext(self, newNext): self.next = newNext class OrderedLinkedList: definit__(self): self.head = None def addToFront (self, item): temp = Node (item) temp.setNext(self.head) self.head = temp Your solution should be a complete method definition with appropriate syntax and indentation. If your method is implemented correctly, then the following assert statements should pass: oll = OrderedLinkedList() assert oll.isDescending() == True oll.addToFront (20) assert oll.isDescending() == True oll.addToFront (25) assert oll.isDescending) == True oll.addToFront(30) assert oll.isDescending) == True oll.addToFront(15) assert oll.isDescending) == False Enter your answer here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
