This commit is contained in:
2025-09-10 17:24:19 +02:00
parent ca552281c9
commit ef135a95e0
6 changed files with 15 additions and 13 deletions

View File

@@ -1,6 +1,3 @@
// Bubblesort Algorithm
// M.Menault 2024
void bubblesort(int* array, int length) void bubblesort(int* array, int length)
{ {
int swapped, i, tmp; int swapped, i, tmp;
@@ -17,5 +14,5 @@ void bubblesort(int* array, int length)
swapped++; swapped++;
} }
} }
} while(swapped==1); } while(swapped > 0);
} }

8
compte_rendu.txt Normal file
View File

@@ -0,0 +1,8 @@
Flat Profile :
Temps et nombre d'éxecution de chaque fonction.
Call Graph :
Voir arbre d'appel + temps et nb d'exec par fonction
Fonction la plus lente : bubblesort
nombre d'appel important de bubblesort dans find_rank_student

BIN
gmon.out Normal file

Binary file not shown.

View File

@@ -1,5 +1,4 @@
// Heapsort Algorithm
// M.Menault 2024
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -47,13 +46,12 @@ void heapsort(int* array, int length)
{ {
int i = 0; int i = 0;
int temp_value = 0; int temp_value = 0;
// Sift the current array (binary tree)
for(i=(length/2); i >= 0; i--) for(i=(length/2); i >= 0; i--)
{ {
sift(array,i,length); sift(array,i,length);
} }
// Heapsort !
for(i=length-1; i > 0; i--) for(i=length-1; i > 0; i--)
{ {
temp_value = array[i]; temp_value = array[i];

BIN
student_rank Executable file

Binary file not shown.

View File

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