This repository is an implementation of three simple sorting algorithms: Bubble Sort, Selection Sort, and Insertion Sort in C. This program will generate 1 million random integer numbers. The numbers are sorted by bubble sort, selection sort and insertion sort and the unsorted and sorted numbers will be saved into a .txt file.
-
Make sure you have the C compiler installed on your system.
-
Clone this repository or download the file
-
Compile the code using the following command:
gcc 2208107010044_Simple_Sorting.c -o sorting
-
Run the compiled result:
./sorting
-
The program will produce an output file in the
output
folder containing the numbers sorted by algorithm type and number.
- Function to save the array into a text file.
- Parameters:
arr
: An array of integer numbers to be saved.n
: The number of elements in the array.filename
: The name of the destination file.
- Function to perform Bubble Sort on the array.
- Parameters:
arr
: An array of integer numbers to be sorted.n
: The number of elements in the array.filename
: The name of the file to store the sort result.
- Function to perform Selection Sort on the array.
- Parameters:
arr
: An array of integer numbers to be sorted.n
: The number of elements in the array.filename
: The name of the file to store the sort result.
- Function to perform Insertion Sort on the array.
- Parameters:
arr
: An array of integer numbers to be sorted.n
: The number of elements in the array.filename
: The name of the file to save the sort result.
- The function to print the table border on the output.
- The main function that initializes variables, generates random numbers, saves to the input file, performs sorting, and prints the execution time result on the table.