Added code for selection sort.

This commit is contained in:
K 2025-01-16 11:00:08 +05:30
parent a348409082
commit 04e40e8623
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F
2 changed files with 44 additions and 0 deletions

41
Codes/Assignment-A3.I.py Normal file
View File

@ -0,0 +1,41 @@
# Assignment-A3.I (Selection Sort)
numbers=[]
# Function to take input for numbers
def input_numbers():
total=int(input("How many numbers you wish to enter?\nTotal numbers:\t"))
for i in range(1, total+1):
numIn=float(input(f"Enter number {i}:\t"))
numbers.append(numIn)
print("The numbers you've entered are:\t", numbers)
# Function for selection sort
def selection():
for i in range(len(numbers)):
min_index=i
for j in range(i+1, len(numbers)):
if numbers[j] < numbers[min_index]:
min_index=j
numbers[i], numbers[min_index] = numbers[min_index], numbers[i]
print("Numbers sorted in ascending order using selection sort:\t", numbers)
def choose_optn():
while True:
print("Choose an option from the menu below:")
print("1 -> Input numbers")
print("2 -> Apply Selection Sorting")
print("3 -> Exit")
optn=int(input("Choose an option (1-3):\t"))
if optn==1:
input_numbers()
elif optn==2:
selection()
elif optn==3:
print("\n## END OF CODE\n")
quit()
else:
print("\nPlease choose a valid option (1-3).\n")
choose_optn()

View File

@ -10,6 +10,9 @@
### Notes ### Notes
### Codes ### Codes
1. [Assignment-A1 (DFS | BFS)]()
2. [Assignment-A2 (A star algorithm)]()
3. [Assignment-A3.I (Selection Sort)](Codes/Assignment-A3.I.py)
### Practical ### Practical