Write a python program to sort a list with n number of elements using Selection Sort

Tech Programmer
0

WRITE A PYTHON PROGRAM TO PERFORM SELECTION SORT TO SORT A LIST WITH  N NUMBER OF ELEMENTS.


CODE FOR THE ABOVE  PYTHON  PROGRAM :


L = []
print("Enter the size of list: "end="")
elements = int(input())
print("Enter"elements"numbers for the list: "end="")
for i in range(elements):
  L.append(int(input()))

for i in range(elements-1):
    ch = 0
    x = L[i]
    for j in range(i+1elements):
        if x > L[j]:
            x = L[j]
            ch = ch + 1
            index = j
    if ch != 0:
        temp = L[i]
        L[i] = x
        L[index] = temp

print("\n Sorted List is: "end="")
for i in range(elements):
    print(L[i], end=" ")


WRITTEN CODE FOR THE ABOVE PROGRAM :


L = []

print("Enter the size of list: ", end="")

elements = int(input())

print("Enter", elements, "numbers for the list: ", end="")

for i in range(elements):

  L.append(int(input()))


for i in range(elements-1):

    ch = 0

    x = L[i]

    for j in range(i+1, elements):

        if x > L[j]:

            x = L[j]

            ch = ch + 1

            index = j

    if ch != 0:

        temp = L[i]

        L[i] = x

        L[index] = temp


print("\n Sorted List is: ", end="")

for i in range(elements):

    print(L[i], end=" ")


OUTPUT :



Post a Comment

0Comments
Post a Comment (0)

Featured Highlighted Categories

You'll discover all of the most up-to-date bring innovative here.

Python List theory with List Programs
Get complete python lists theory and list basic and insane programs for your practice.
CBSE SAMPLE PAPERS
Get CBSE sample and question papers of last 7 years with answers to get best practice for your Board Exams
Python String theory and String Programs
Python strings complete theory with illustrations and practice programs for free