/Sort-Function

Selection Sort - sort a list without using ".sort( )"

Primary LanguagePythonMIT LicenseMIT

Selection Sort in Python

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.

How the Selection Sort Works

  1. An unsorted list, old_list, is provided with a set of numbers.
  2. An empty list, new_list, is created to store the sorted elements.
  3. The script iterates over the old_list until it's empty.
  4. In each iteration, it finds the minimum element in the old_list.
  5. The minimum element is removed from the old_list and appended to the new_list.
  6. The process continues until all elements are sorted, and the new_list contains the sorted elements in ascending order.

Usage

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.

Features

  • Efficient sorting algorithm for small to medium-sized lists.
  • Sorts elements in ascending order.

How to Run

  1. Make sure you have Python installed on your system.
  2. Download the selection_sort.py file.
  3. Open a terminal or command prompt.
  4. Navigate to the directory where selection_sort.py is located.
  5. 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