Merge branch 'master' of https://codefirst.iut.uca.fr/git/thibaud.la_riviere-gillet/SAE_S1.02_Comparaison_d_approches_algorithmiques
commit
706b55be13
@ -0,0 +1,10 @@
|
||||
Fondation Structure
|
||||
Structure Electricite
|
||||
Structure Plomberie
|
||||
Plomberie Murs
|
||||
Electricite Menuiserie
|
||||
Plomberie Sols
|
||||
Murs Peinture
|
||||
Peinture Finitions
|
||||
Sols Finitions
|
||||
|
@ -0,0 +1,86 @@
|
||||
#include "../includes/"
|
||||
|
||||
void fusion(int R[], int tR, int S[], int tS, int T[])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int tlog;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
tlog = tR + tS;
|
||||
while (i < tR && j <= tS)
|
||||
{
|
||||
if (R[i] < S[j])
|
||||
{
|
||||
T[k] = R[i];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
T[k] = S[j];
|
||||
j++;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
while (i < tR)
|
||||
{
|
||||
T[k] = R[i];
|
||||
i++;
|
||||
k++;
|
||||
}
|
||||
while (j < tS)
|
||||
{
|
||||
T[k] = S[j];
|
||||
j++;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
void copy(int T[], int i, int j, int R[])
|
||||
{
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
while (i < j)
|
||||
{
|
||||
R[k] = T[i];
|
||||
i++;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
void triFusion(int T[], int tlog)
|
||||
{
|
||||
int *R;
|
||||
int *S;
|
||||
|
||||
if (tlog == 1)
|
||||
return;
|
||||
R = (int *)malloc(sizeof (int) * (tlog / 2));
|
||||
S = (int *)malloc(sizeof (int) * tlog - tlog/2);
|
||||
if (!R || !S)
|
||||
exit (1);
|
||||
copy (T, 0, tlog/2, R);
|
||||
copy (T, tlog/2, tlog, S);
|
||||
triFusion (R, tlog/2);
|
||||
triFusion (S, tlog - tlog/2);
|
||||
fusion (R, tlog/2, S, tlog - tlog/2, T);
|
||||
free (R);
|
||||
free (S);
|
||||
}
|
||||
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int tab[10] = {10, 0, 2, 15, 7, 5 ,68, 1, 7 ,8};
|
||||
int tlog = 10;
|
||||
int i = 0;
|
||||
|
||||
triFusion(tab, tlog);
|
||||
while (i < tlog)
|
||||
printf ("%d : ", tab[i++]);
|
||||
printf ("\n");
|
||||
return (0);
|
||||
}
|
Loading…
Reference in new issue