|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
#include "../includes/ft.h"
|
|
|
|
|
#include "../includes/"
|
|
|
|
|
|
|
|
|
|
void fusion(int R[], int tR, int S, int tS, int T[])
|
|
|
|
|
void fusion(int R[], int tR, int S[], int tS, int T[])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
@ -19,14 +19,14 @@ void fusion(int R[], int tR, int S, int tS, int T[])
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
t[k] = S[j];
|
|
|
|
|
T[k] = S[j];
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
while (i < tR)
|
|
|
|
|
{
|
|
|
|
|
t[k] = R[i];
|
|
|
|
|
T[k] = R[i];
|
|
|
|
|
i++;
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
@ -41,11 +41,14 @@ void fusion(int R[], int tR, int S, int tS, int T[])
|
|
|
|
|
void copy(int T[], int i, int j, int R[])
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
for (k = i; i = 0; k < j; k++, i++)
|
|
|
|
|
R[i] = T[k];
|
|
|
|
|
k = 0;
|
|
|
|
|
while (i < j)
|
|
|
|
|
{
|
|
|
|
|
R[k] = T[i];
|
|
|
|
|
i++;
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void triFusion(int T[], int tlog)
|
|
|
|
@ -59,12 +62,25 @@ void triFusion(int T[], int tlog)
|
|
|
|
|
S = (int *)malloc(sizeof (int) * tlog - tlog/2);
|
|
|
|
|
if (!R || !S)
|
|
|
|
|
exit (1);
|
|
|
|
|
copy (T, 0, n/2, R);
|
|
|
|
|
copy (T, n/2, n, S);
|
|
|
|
|
triFusion (R, n/2);
|
|
|
|
|
triFusion (S, n - n/2, T);
|
|
|
|
|
fusion (R, n/2, S, n - n/2, T);
|
|
|
|
|
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)
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|