Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (3)
all: main
main : tris.o main.c
gcc -o main -Wall tris.o -g main.c
tris.o : tris.c tris.h
gcc -c -Wall -g tris.c
clean :
rm *.o
File added
#include <stdio.h>
#include "tris.h"
int main() {
long A[5] = {3, 4, 1, 6, -1};
triFusion(A, 5);
for(int i = 0; i < 5; ++i) {
printf("%i\n", A[i]);
}
return 0;
}
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tris.h"
/*triInsertion(A,n){
for(size_t i = 1; i <= n-1; i++){
clef = A[i];
j = i - 1;
while(j >= 0 && A[j] > clé){
A[j+1] = A[j];
j--;
}
A[j+1] = clef;
}
}*/
void triFusion(long* A, size_t size) {
sousTriFusion(A, 0, size);
printf("Tri fusion\n");
}
void sousTriFusion(long* A, size_t first, size_t size) {
if(first<size-1){
size_t middle = floor((first+size)/2);
sousTriFusion(A, first, middle);
sousTriFusion(A, middle, size);
fusion(A, first, middle, size);
}
printf("Sous Tri fusion\n");
}
void copySousTable(long* mainT, long* underT, size_t id, size_t size) {
size_t i = 0;
for(; id < size; ++id) {
mainT[id] = underT[i];
}
}
void fusion(long* A, size_t first, size_t middle, size_t size) {
size_t n1 = middle - first; // Nb elem dans A[p , q] q exclu
size_t n2 = size - middle; // Nb elem dans A[q , r] r exclu
size_t indg = 0;
size_t indd = 0;
long* ag = malloc(sizeof(long) * n1);
long* ad = malloc(sizeof(long) * n2);
printf("Malloc\n");
copySousTable(A, ag, first, n1);
copySousTable(A, ad, middle, n2);
printf("CopySousTable\n");
int i = first;
while(i < size) {
if(indg == n1) {
A[i] = ad[indd];
indd++;
}
else if(indd == n2) {
A[i] = ag[indg];
indg++;
}
else if(ag[indg] < ad[indd]) {
A[i] = ag[indg];
indg++;
}
else {
A[i] = ag[indg];
indd++;
}
++i;
}
free(ag);
free(ad);
}
#ifndef TRIS_H
#define TRIS_H
void triFusion(long* A, size_t size);
void sousTriFusion(long* A, size_t first, size_t size);
void fusion(long* A, size_t first, size_t middle, size_t size);
#endif //TRIS_H
File added
#include <stdio.h>
int main( int argc, const char* argv[] )
{
}