Ask Question
11 March, 23:55

Write me some pseudocode for one pass of the Selection Sort algorithm through random values stored in an Unordered-List, or Linked-List, of values (rather than a standard "Python" List).

• How would you implement a swap using a Linked-List?

• What is the minimum number of variables required?

+4
Answers (1)
  1. 12 March, 00:23
    0
    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. dа ta:

    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)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write me some pseudocode for one pass of the Selection Sort algorithm through random values stored in an Unordered-List, or Linked-List, of ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers