|
|
|
@ -1,35 +1,37 @@
|
|
|
|
|
#include "../includes/"
|
|
|
|
|
#include "../includes/recherche.h"
|
|
|
|
|
#include "../includes/structures.h"
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
k = 0;
|
|
|
|
|
while (i < tR && j < tS)
|
|
|
|
|
{
|
|
|
|
|
if (R[i] < S[j])
|
|
|
|
|
{
|
|
|
|
|
T[k] = R[i];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
T[k] = S[j];
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (i < tR)
|
|
|
|
|
{
|
|
|
|
|
T[k] = R[i];
|
|
|
|
|
i++;
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (j < tS)
|
|
|
|
|
{
|
|
|
|
|
T[k] = S[j];
|
|
|
|
@ -41,7 +43,7 @@ void fusion(int R[], int tR, int S[], int tS, int T[])
|
|
|
|
|
void copy(int T[], int i, int j, int R[])
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
while (i < j)
|
|
|
|
|
{
|
|
|
|
@ -56,31 +58,38 @@ void triFusion(int T[], int tlog)
|
|
|
|
|
int *R;
|
|
|
|
|
int *S;
|
|
|
|
|
|
|
|
|
|
if (tlog == 1)
|
|
|
|
|
if (tlog <= 1)
|
|
|
|
|
return;
|
|
|
|
|
R = (int *)malloc(sizeof (int) * (tlog / 2));
|
|
|
|
|
S = (int *)malloc(sizeof (int) * tlog - tlog/2);
|
|
|
|
|
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);
|
|
|
|
|
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 main(void)
|
|
|
|
|
{
|
|
|
|
|
int tab[10] = {10, 0, 2, 15, 7, 5 ,68, 1, 7 ,8};
|
|
|
|
|
int tab[10] = {10, 0, 2, 15, 7, 5, 68, 1, 7, 8};
|
|
|
|
|
int tlog = 10;
|
|
|
|
|
int i = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("Avant le tri : \n\t");
|
|
|
|
|
for (i = 0; i < tlog; i++)
|
|
|
|
|
printf("%d, ", tab[i]);
|
|
|
|
|
|
|
|
|
|
triFusion(tab, tlog);
|
|
|
|
|
while (i < tlog)
|
|
|
|
|
printf ("%d : ", tab[i++]);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
|
|
printf("\nApres le tri : \n\t");
|
|
|
|
|
for (i = 0; i < tlog; i++)
|
|
|
|
|
printf("%d, ", tab[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|