Professional Documents
Culture Documents
Act1 32
Act1 32
DATE: 30-12-2020
ACTIVITY-1.31
Example:
Python program for implementation of Selection Sort
def selectionSort(itemsList):
n=len(itemsList)
for i in range(n-1):
minValueIndex=i
for j in range(i+1, n):
if itemsList[j]<itemsList[minValueIndex]:
minValueIndex=j
if minValueIndex != i:
temp=itemsList[i]
itemsList[i]=itemsList[minValueIndex]
itemsList[minValueIndex]=temp
return itemsList
list_numbers=[20, -5, 86, 354, 100, -400, 231, 8, 1]
print("\nList before sorting")
print(list_numbers)
print("\nList after applying Selection sort technique:")
print(selectionSort(list_numbers))
DASARI VIJAYASREE
REG NO: 20MIS0280
ACTIVITY:
1) Write an algorithm for selection sorting technique.
STEP 1: Start
STEP 2: Set MIN to location 0
STEP 3: Search the minimum element in the list
STEP 4: Swap with value at location MIN
STEP 5: Increment MIN to point to next element
STEP 6: Repeat until list is sorted
STEP 7: Stop
e) Take the even numbers from list_numbers and store them into a
file (say ‘even_numbers.txt’).
print("\n***************\n")
list_numbers=[432, 54, -23, 9, 0, 100]
f=open("even_numbers.txt")
for x in f:
print(x)
f.close()
f=open("even_numbers.txt","a")
DASARI VIJAYASREE
REG NO: 20MIS0280
f.write("0, 54, 100, 432")
f.close()
print("even_numbers")
f=open("even_numbers.txt")
print(f.read())
f.close()
print("\n***************\n")
f) Take the odd numbers from list_numbers and store them into a file
(say ‘odd_numbers.txt’).
print("\n***************\n")
list_numbers=[432, 54, -23, 9, 0, 100]
f=open("odd_numbers.txt")
for x in f:
print(x)
f.close()
DASARI VIJAYASREE
REG NO: 20MIS0280
f=open("odd_numbers.txt","a")
f.write("-23, 9")
f.close()
print("odd_numbers")
f=open("odd_numbers.txt")
print(f.read())
f.close()
print("\n***************\n")