This commit is contained in:
Maxime Menault 2024-09-03 08:26:03 +02:00
parent fe64cb7aa5
commit b8c6f517fc
3 changed files with 30 additions and 2 deletions

21
bubblesort.c Normal file
View File

@ -0,0 +1,21 @@
// Bubblesort Algorithm
// M.Menault 2024
void bubblesort(int* array, int length)
{
int swapped, i, tmp;
do
{
swapped = 0;
for(i=1;i<length;i++)
{
if(array[i-1] > array[i])
{
tmp = array[i-1];
array[i-1] = array[i];
array[i] = tmp;
swapped++;
}
}
} while(swapped==1);
}

6
bubblesort.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __BUBBLESORT__
#define __BUBBLESORT__
void bubblesort(int* array, int length);
#endif

View File

@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "heapsort.h"
#include "bubblesort.h"
void generate_grades(int** students_array, int students_number, int grades_number)
{
@ -54,7 +55,7 @@ int find_rank_student(int student_grade, int* grades_array, int students_number)
{
int position = -1;
int i = 0;
heapsort(grades_array,students_number);
bubblesort(grades_array,students_number);
for(i = students_number-1; i >= 0; i--)
{
if(grades_array[i] == student_grade)
@ -76,7 +77,7 @@ void sort_students(int** students_rank, int** students_array, int students_numbe
{
grades[j] = students_array[j][i];
}
heapsort(grades,students_number);
bubblesort(grades,students_number);
for(j = 0; j < students_number; j++)
{
students_rank[j][i] = find_rank_student(students_array[j][i],grades,students_number);