Skip to content
Snippets Groups Projects
Commit 2601114b authored by chafiol's avatar chafiol
Browse files

1er rendu sans readme

parent 05f56597
No related merge requests found
No preview for this file type
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
void triInsertion(long* A, size_t n){ void triInsertion(long* A, size_t n){
long cle = 0; long cle = 0;
size_t max = 0; size_t max = 0; max--;
max--;
for(size_t i = 1; i<n; i++){ for(size_t i = 1; i<n; i++){
cle=A[i]; cle=A[i];
size_t j = i - 1; size_t j = i - 1;
...@@ -75,33 +74,30 @@ void triFusion(long * A, size_t n){ ...@@ -75,33 +74,30 @@ void triFusion(long * A, size_t n){
} }
void sousTriRapide(long* A, size_t p, size_t r) { void sousTriRapide(long* A, size_t p, size_t r) {
if (p<(r-1)) { size_t max = 0; max--;
size_t q = partition(A, p, r); if(r-1 != max){
sousTriRapide(A, p, q); if (p<(r-1)) {
sousTriRapide(A, q+1, r); 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) { size_t partition(long* A, size_t p, size_t r) {
printf("r >>>>>>>>>> %d\n", r); long pivot = A[r-1];
size_t max = 0;
max--;
size_t pivot = 0;
if(r-1 != max){
pivot = A[r-1];
}
size_t i = p; size_t i = p;
long temp; for (size_t j = p; j <= r-2; j++) {
for (size_t j = p; j < r-2; j++) {
if (A[j] <= pivot) { if (A[j] <= pivot) {
temp = A[i]; long temp = A[i];
A[i] = A[j]; A[i] = A[j];
A[j] = temp; A[j] = temp;
i++; i++;
} }
} }
temp = A[i]; long temp = A[i];
A[i] = A[r-1]; A[i] = A[r-1];
A[r-1] = temp; A[r-1] = temp;
return i; return i;
......
No preview for this file type
...@@ -17,7 +17,7 @@ int readToTab(long* tab, char* file){ ...@@ -17,7 +17,7 @@ int readToTab(long* tab, char* file){
if(temp != ' '){ if(temp != ' '){
tmp[x] = temp; tmp[x] = temp;
x++; x++;
n++;
} }
else if(temp == ' '){ else if(temp == ' '){
long t = atol(tmp); long t = atol(tmp);
...@@ -25,6 +25,7 @@ int readToTab(long* tab, char* file){ ...@@ -25,6 +25,7 @@ int readToTab(long* tab, char* file){
memset(tmp, 0, 1000); memset(tmp, 0, 1000);
j++; j++;
x=0; x=0;
n++;
} }
read(fd,&temp,sizeof(char)); read(fd,&temp,sizeof(char));
} }
...@@ -44,7 +45,7 @@ int main(int argc, char **argv){ ...@@ -44,7 +45,7 @@ int main(int argc, char **argv){
} }
printf("\n"); printf("\n");
if((strcmp(argv[1], "--insertion") == 0)){ if((strcmp(argv[1], "--insertion") == 0) || strcmp(argv[1], "-i")== 0){
triInsertion(tab, n); triInsertion(tab, n);
printf("Insertion : "); printf("Insertion : ");
for(int i = 0; i<n; i++){ for(int i = 0; i<n; i++){
...@@ -52,7 +53,7 @@ int main(int argc, char **argv){ ...@@ -52,7 +53,7 @@ int main(int argc, char **argv){
} }
printf("\n"); printf("\n");
} }
else if((strcmp(argv[1], "--fusion")== 0)){ else if(strcmp(argv[1], "--fusion")== 0 || strcmp(argv[1], "-f")== 0){
triFusion(tab, n); triFusion(tab, n);
printf("Fusion : "); printf("Fusion : ");
for(int i = 0; i<n; i++){ for(int i = 0; i<n; i++){
...@@ -60,9 +61,30 @@ int main(int argc, char **argv){ ...@@ -60,9 +61,30 @@ int main(int argc, char **argv){
} }
printf("\n"); printf("\n");
} }
else if((strcmp(argv[1], "--rapide")== 0)){ else if((strcmp(argv[1], "--rapide")== 0) || strcmp(argv[1], "-r")== 0){
triRapide(tab, n);
printf("Rapide : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
}
printf("\n");
}
else if (strcmp(argv[1], "-a") == 0)
{
triInsertion(tab, n);
printf("Insertion : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
}
printf("\n");
triFusion(tab, n);
printf("Fusion : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
}
printf("\n");
triRapide(tab, n); triRapide(tab, n);
printf("Rapide : "); printf("Rapide : ");
for(int i = 0; i<n; i++){ for(int i = 0; i<n; i++){
printf("%ld,", tab[i]); printf("%ld,", tab[i]);
} }
......
all: algo all: tri
algo: main.c algos.o tri: main.c algos.o
gcc -Wall main.c algos.o -Wall gcc -Wall main.c algos.o -Wall -o tri
algos: algos.c algos.h algos: algos.c algos.h
gcc -c algos.c algos.h -Wall gcc -c algos.c algos.h -Wall
......
40 47 12 2 25 3 14 65 48 10 1 56 94 45 36 27 6 7 19 16 24 38 37 11 78 5 18 54 20 21 82 42 32 22 19 9 53 41 99 125 111 248 33 .
\ No newline at end of file
40 47 12 2 25 3 14 65 48 10 1 56 94 45 36 27 6 7 19 16 24 38 37 11 .
\ No newline at end of file
File moved
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