Fix
This commit is contained in:
parent
fe64cb7aa5
commit
b8c6f517fc
21
bubblesort.c
Normal file
21
bubblesort.c
Normal 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
6
bubblesort.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __BUBBLESORT__
|
||||||
|
#define __BUBBLESORT__
|
||||||
|
|
||||||
|
void bubblesort(int* array, int length);
|
||||||
|
|
||||||
|
#endif
|
@ -4,6 +4,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "heapsort.h"
|
#include "heapsort.h"
|
||||||
|
#include "bubblesort.h"
|
||||||
|
|
||||||
void generate_grades(int** students_array, int students_number, int grades_number)
|
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 position = -1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
heapsort(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)
|
||||||
@ -76,7 +77,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];
|
||||||
}
|
}
|
||||||
heapsort(grades,students_number);
|
bubblesort(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);
|
||||||
|
Loading…
Reference in New Issue
Block a user