Expected Behavior Write a Python method sort() to sort a LinkedList object in de
ID: 3736227 • Letter: E
Question
Expected Behavior
Write a Python method sort() to sort a LinkedList object in descending order of the attribute _value. The code for the LinkedList class is shown below. You should use the sorting algorithm described here.
Given a LinkedList object llist, the execution of the code
llist.sort()
print(llist)
should cause the sorted list to be printed out.
The code for the LinkedList class is as follows:
Examples
Code:
ll = LinkedList()
ll.add(Node(1))
ll.add(Node(3))
ll.add(Node(2))
ll.sort()
print(ll)
Result: (this is the string returned by the __str__() method for the LinkedList class)
List[ 3; 2; 1; ]
Code:
ll = LinkedList()
ll.sort()
print(ll)
Result:
List[ ]
Code:
ll = LinkedList()
ll = LinkedList()
ll.add(Node(1))
ll.add(Node(1))
ll.add(Node(1))
ll.sort()
print(ll)
Result:
List[ 1; 1; 1; ]