Answer:
Minimum of 6 variables is required
Explanation:
class LinkedList:
def __init__(self, v):
self.data = v
self.next = None
def sortSelections(first):
x = y = first
while y.next:
z = p = y.next
while p:
if y.data > p.data:
if y.next == p:
if y == first:
y.next = p.next
p.next = y
y, p = p, y
z = p
first = y
p = p.next
else:
y.next = p.next
p.next = y
x.next = p
y, p = p, y
z = p
p = p.next
else:
if y == first:
r = y.next
y.next = p.next
p.next = r
z.next = y
y, p = p, y
z = p
p = p.next
first = y
else:
r = y.next
y.next = p.next
p.next = r
z.next = y
x.next = p
y, p = p, y
z = p
p = p.next
else:
z = p
p = p.next
x = y
y = y.next
return first
def display(first):
while first:
print(first.data, end = " ")
first = first.next
if __name__ == "__main__":
print("Sorted List: ")
first = LinkedList(53)
first.next = LinkedList(14)
first.next.next = LinkedList(2)
first.next.next.next = LinkedList(9)
first.next.next.next.next = LinkedList(92)
first = sortSelections(first)
display(first)