This Python script demonstrates the selection sort algorithm to arrange a list of numbers in ascending order. The selection sort algorithm repeatedly finds the minimum element from the unsorted part of the list and appends it to a new list, effectively sorting the elements.
- An unsorted list,
old_list
, is provided with a set of numbers. - An empty list,
new_list
, is created to store the sorted elements. - The script iterates over the
old_list
until it's empty. - In each iteration, it finds the minimum element in the
old_list
. - The minimum element is removed from the
old_list
and appended to thenew_list
. - The process continues until all elements are sorted, and the
new_list
contains the sorted elements in ascending order.
To sort a list of numbers using the selection sort algorithm, you can provide your list in the old_list
variable and run the Python script.
- Efficient sorting algorithm for small to medium-sized lists.
- Sorts elements in ascending order.
- Make sure you have Python installed on your system.
- Download the
selection_sort.py
file. - Open a terminal or command prompt.
- Navigate to the directory where
selection_sort.py
is located. - Run the sorting algorithm by executing the command:
python selection_sort.py
.
Witness the selection sort algorithm in action as it arranges your list in ascending order!
For more Python projects and algorithms, visit my GitHub profile: https://github.com/nisal2002