This repository demonstrates the implementation of sorting algorithms in C, organized into a reusable library. The project includes two sorting methods: Bubble Sort and Quick Sort, for both integer and floating-point arrays. The library is modular, with separate files for headers and implementations, and is designed to ensure clean and maintainable code.
- Bubble Sort
- Sorts arrays of integers and floats using the Bubble Sort algorithm.
- Quick Sort
- Sorts arrays of integers and floats using the Quick Sort algorithm.
- Organized library structure for reuse.
- Separate folders for header files (
headers/
) and implementations.
.
├── headers/
│ ├── bubble_sort.c # Bubble Sort implementation
│ ├── quick_sort.c # Quick Sort implementation
│ ├── sorting.h # Header file for the sorting library
├── main.c # Main program demonstrating the library
├── CMakeLists.txt # Build file for CMake
└── README.md # Project documentation
Ensure you have the following installed:
- GCC (GNU Compiler Collection)
- CMake (version 3.10 or newer)
-
Clone the Repository
git clone <repository-url> cd <repository-folder>
-
Create a Build Directory
mkdir build cd build
-
Generate the Build Files
cmake ..
-
Compile the Project
make
-
Run the Executable
./main
Function | Description |
---|---|
void bubbleSortInt(int *arr, int n) |
Sorts an array of integers in ascending order using Bubble Sort. |
void bubbleSortFloat(float *arr, int n) |
Sorts an array of floats in ascending order using Bubble Sort. |
void quickSortInt(int *arr, int low, int high) |
Sorts an array of integers in ascending order using Quick Sort. |
void quickSortFloat(float *arr, int low, int high) |
Sorts an array of floats in ascending order using Quick Sort. |
For the main.c
program:
Original array: 5 3 8 4 2
Sorted array using Bubble Sort: 2 3 4 5 8
Sorted array using Quick Sort: 1 5 7 8 9 10
- Adding New Sorting Algorithms
- Create a new
.c
file for the algorithm in theheaders/
folder. - Add the function prototypes to
sorting.h
. - Include the implementation in the library (
CMakeLists.txt
).
- Create a new
This project is licensed under the MIT License. See the LICENSE file for details.
Happy Coding!