This repository contains a C implementation of the Selection Sort algorithm. Selection Sort is a simple comparison-based sorting algorithm that divides the input array into a sorted and an unsorted region. The algorithm repeatedly selects the smallest (or largest) element from the unsorted region and swaps it with the first unsorted element.
Selection Sort is a straightforward sorting algorithm with a time complexity of O(n^2) in the worst case. It is often inefficient on large datasets compared to more advanced algorithms. However, its simplicity makes it easy to understand and implement.
This implementation consists of three files:
selectionsort.h
: Header file declaring the Selection Sort function.selectionsort.c
: Implementation of the Selection Sort algorithm.selectionsortmain.c
: Test file to demonstrate the usage of Selection Sort.
To use the Selection Sort algorithm, follow these steps:
- Clone this repository:
git clone https://github.com/excel-asaph/Selection-Sort-Algorithm-Implementation.git
cd Selection-Sort-Algorithm-Implementation
- Compile the program:
gcc selectionsortmain.c selectionsort.c -o selectionsort
- Run the executable:
./selectionsort
#ifndef SELECTIONSORT_H
#define SELECTIONSORT_H
#include <stdio.h>
/**
* @file selectionsort.h
* @brief Header file for the Selection Sort algorithm.
*/
/**
* @brief Sorts an array in ascending order using the Selection Sort algorithm.
*
* @param arr An array to be sorted.
* @param size The size of the array.
*/
void selectionsort(int arr[], int size);
#endif
#include "selectionsort.h"
/**
* @file selectionsort.c
* @brief Implementation of the Selection Sort algorithm.
*/
/**
* @brief Sorts an array in ascending order using the Selection Sort algorithm.
*
* @param arr An array to be sorted.
* @param n The size of the array.
*/
void selectionsort(int arr[], int n) {
// Implementation details...
}
#include "selectionsort.h"
/**
* @file selectionsortmain.c
* @brief Test file for the Selection Sort algorithm.
*/
// Main function and usage details...
Selection Sort has a time complexity of O(n^2) in the worst case, making it less suitable for large datasets. Its simplicity, however, makes it a good educational algorithm.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/new-feature
) - Make your changes and commit them (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/new-feature
) - Create a pull request
This project is licensed under the MIT License - see the LICENSE file for details.