Skip to content
Snippets Groups Projects
Commit e212021d authored by Mickael Da Silva's avatar Mickael Da Silva
Browse files

Tris dans fichiers

parent 79192923
No related merge requests found
#include "algos.h"
#include "triInsertion.h"
#include "triFusion.h"
#include "triRapide.h"
int readToTab(long* tab, char* file){
int n = 0;
......@@ -55,7 +58,7 @@ int main(int argc, char **argv){
}
else if(strcmp(argv[1], "--fusion")== 0 || strcmp(argv[1], "-f")== 0){
triFusion(tab, n);
printf("Fusion : ");
printf("Fusion : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
}
......
all: tri
tri: main.c algos.o
gcc -Wall main.c algos.o -Wall -o tri
tri: main.c triInsertion.o triFusion.o triRapide.o
gcc -Wall main.c triInsertion.o triFusion.o triRapide.o -Wall -o tri
algos: algos.c algos.h
gcc -c algos.c algos.h -Wall
insertion: triInsertion.c triInsertion.h
gcc -c triInsertion.c triInsertion.h -Wall
fusion: triFusion.c triFusion.h
gcc -c triFusion.c triFusion.h -Wall
rapide: triRapide.c triRapide.h
gcc -c triRapide.c triRapide.h -Wall
clear:
rm *.o
\ No newline at end of file
No preview for this file type
#include "triFusion.h"
void sousTriFusion(long * A, size_t p, size_t r){
if(p<(r-1)){
size_t q = (size_t)((p+r)/2);
sousTriFusion(A, p, q);
sousTriFusion(A, q, r);
fusion(A, p, q, r);
}
}
void fusion(long * A, size_t p, size_t q, size_t r){
size_t n1 = q-p;
size_t n2 = r-q;
long Ad[n2];
memset(Ad, 0, n2);
int j =0;
for(size_t i = q; i<r; i++){
Ad[j] = A[i];
j++;
}
long Ag[n1];
memset(Ag, 0, n1);
j =0;
for(size_t i = p; i<q; i++){
Ag[j] = A[i];
j++;
}
size_t indg = 0;
size_t indd = 0;
size_t i = p;
while (i < r){
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] = Ad[indd];
indd++;
}
i++;
}
}
void triFusion(long * A, size_t n){
sousTriFusion(A, 0, n);
}
\ No newline at end of file
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
void sousTriFusion(long * A, size_t p, size_t r);
void fusion(long * A, size_t p, size_t q, size_t r);
void triFusion(long * A, size_t n);
\ No newline at end of file
File added
#include "triInsertion.h"
void triInsertion(long* A, size_t n){
long cle = 0;
size_t max = 0; max--;
for(size_t i = 1; i<n; i++){
cle=A[i];
size_t j = i - 1;
while (j != max && A[j] > cle ){
A[j+1] = A[j];
j = j-1;
}
A[j+1] = cle;
}
}
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
void triInsertion(long* A, size_t n);
\ No newline at end of file
File added
#include "triRapide.h"
void sousTriRapide(long* A, size_t p, size_t r) {
size_t max = 0; max--;
if(r-1 != max){
if (p<(r-1)) {
size_t q = partition(A, p, r);
sousTriRapide(A, p, q);
sousTriRapide(A, q+1, r);
}
}
}
size_t partition(long* A, size_t p, size_t r) {
long pivot = A[r-1];
size_t i = p;
for (size_t j = p; j <= r-2; j++) {
if (A[j] <= pivot) {
long temp = A[i];
A[i] = A[j];
A[j] = temp;
i++;
}
}
long temp = A[i];
A[i] = A[r-1];
A[r-1] = temp;
return i;
}
void triRapide(long* A, size_t n) {
sousTriRapide(A, 0, n);
}
\ No newline at end of file
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
void triRapide(long* A, size_t n);
size_t partition(long* A, size_t p, size_t r);
void sousTriRapide(long* A, size_t p, size_t r);
File added
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment