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
Showing
with 2241 additions and 0 deletions
#!/bin/bash
for i in "insertion" "fusion" "rapide"
do
echo $i
cmd=$(for j in `seq 1 $3`
do
../tri -g $2 $1 1>../tabs/hypo_tab.txt
../tri --$i ../tabs/hypo_tab.txt
done )
time $cmd
done
\ No newline at end of file
sort iTest taille tri temps mem
Aleatoire 1 81074 insertion 5.04 1712
Aleatoire 1 81074 fusion 0.11 14872
Aleatoire 1 81074 rapide 6.46 5200
Aleatoire 1 81074 bulle 5.18 1360
Trie 1 81074 insertion 0.09 1720
Trie 1 81074 fusion 0.12 14868
Trie 1 81074 rapide 13.96 6636
Trie 1 81074 bulle 8.42 1356
Trie_inverse 1 81074 insertion 9.93 1736
Trie_inverse 1 81074 fusion 0.16 18248
Trie_inverse 1 81074 rapide 0.15 1888
Trie_inverse 1 81074 bulle 34.39 1880
Trie_partiel 1 81074 insertion 3.99 1712
Trie_partiel 1 81074 fusion 0.17 14936
Trie_partiel 1 81074 rapide 0.10 1672
Trie_partiel 1 81074 bulle 19.95 1832
Aleatoire 2 11196 insertion 0.11 1304
Aleatoire 2 11196 fusion 0.01 2884
Aleatoire 2 11196 rapide 0.00 1444
Aleatoire 2 11196 bulle 0.40 1452
Trie 2 11196 insertion 0.00 1364
Trie 2 11196 fusion 0.02 3068
Trie 2 11196 rapide 0.27 2056
Trie 2 11196 bulle 0.20 1444
Trie_inverse 2 11196 insertion 0.20 1412
Trie_inverse 2 11196 fusion 0.01 2992
Trie_inverse 2 11196 rapide 0.21 2048
Trie_inverse 2 11196 bulle 0.31 1412
Trie_partiel 2 11196 insertion 0.09 1412
Trie_partiel 2 11196 fusion 0.01 2944
Trie_partiel 2 11196 rapide 0.02 1476
Trie_partiel 2 11196 bulle 0.33 1304
Aleatoire 3 23839 insertion 0.45 1364
Aleatoire 3 23839 fusion 0.04 4848
Aleatoire 3 23839 rapide 0.03 1336
Aleatoire 3 23839 bulle 1.89 1388
Trie 3 23839 insertion 0.04 1272
Trie 3 23839 fusion 0.05 4964
Trie 3 23839 rapide 1.26 2704
Trie 3 23839 bulle 0.87 1272
Trie_inverse 3 23839 insertion 0.84 1388
Trie_inverse 3 23839 fusion 0.01 4892
Trie_inverse 3 23839 rapide 0.60 2148
Trie_inverse 3 23839 bulle 1.41 1356
Trie_partiel 3 23839 insertion 0.33 1396
Trie_partiel 3 23839 fusion 0.02 4940
Trie_partiel 3 23839 rapide 0.03 1316
Trie_partiel 3 23839 bulle 1.58 1272
Aleatoire 4 15670 insertion 0.21 1448
Aleatoire 4 15670 fusion 0.01 3696
Aleatoire 4 15670 rapide 0.03 1396
Aleatoire 4 15670 bulle 0.79 1512
Trie 4 15670 insertion 0.01 1444
Trie 4 15670 fusion 0.01 3696
Trie 4 15670 rapide 0.53 2488
Trie 4 15670 bulle 0.38 1440
Trie_inverse 4 15670 insertion 0.38 1344
Trie_inverse 4 15670 fusion 0.02 3776
Trie_inverse 4 15670 rapide 0.30 2216
Trie_inverse 4 15670 bulle 0.60 1340
Trie_partiel 4 15670 insertion 0.15 1396
Trie_partiel 4 15670 fusion 0.02 3744
Trie_partiel 4 15670 rapide 0.02 1448
Trie_partiel 4 15670 bulle 0.67 1456
Aleatoire 5 68921 insertion 3.63 1668
Aleatoire 5 68921 fusion 0.10 12724
Aleatoire 5 68921 rapide 0.09 1732
Aleatoire 5 68921 bulle 16.40 1620
Trie 5 68921 insertion 0.05 1620
Trie 5 68921 fusion 0.13 12712
Trie 5 68921 rapide 10.64 5964
Trie 5 68921 bulle 7.30 1684
Trie_inverse 5 68921 insertion 7.66 1672
Trie_inverse 5 68921 fusion 0.14 17192
Trie_inverse 5 68921 rapide 0.16 1644
Trie_inverse 5 68921 bulle 33.93 1876
Trie_partiel 5 68921 insertion 3.06 1716
Trie_partiel 5 68921 fusion 0.08 12712
Trie_partiel 5 68921 rapide 0.08 1728
Trie_partiel 5 68921 bulle 14.48 1636
Aleatoire 6 83948 insertion 5.41 1668
Aleatoire 6 83948 fusion 0.13 15400
Aleatoire 6 83948 rapide 0.12 1624
Aleatoire 6 83948 bulle 25.10 1668
Trie 6 83948 insertion 0.14 1668
Trie 6 83948 fusion 0.13 15456
Trie 6 83948 rapide 15.45 7144
Trie 6 83948 bulle 11.25 1832
Trie_inverse 6 83948 insertion 11.15 1820
Trie_inverse 6 83948 fusion 0.09 15456
Trie_inverse 6 83948 rapide 4.93 3620
Trie_inverse 6 83948 bulle 18.37 1916
Trie_partiel 6 83948 insertion 4.40 1860
Trie_partiel 6 83948 fusion 0.09 15348
Trie_partiel 6 83948 rapide 0.09 1624
Trie_partiel 6 83948 bulle 22.37 1724
Aleatoire 7 36784 insertion 1.17 1464
Aleatoire 7 36784 fusion 0.04 7020
Aleatoire 7 36784 rapide 0.06 1448
Aleatoire 7 36784 bulle 5.01 1360
Trie 7 36784 insertion 0.06 1476
Trie 7 36784 fusion 0.06 7100
Trie 7 36784 rapide 3.11 3652
Trie 7 36784 bulle 2.25 1360
Trie_inverse 7 36784 insertion 2.34 1412
Trie_inverse 7 36784 fusion 0.16 16496
Trie_inverse 7 36784 rapide 9.07 5308
Trie_inverse 7 36784 bulle 20.72 1904
Trie_partiel 7 36784 insertion 0.87 1380
Trie_partiel 7 36784 fusion 0.08 6992
Trie_partiel 7 36784 rapide 0.06 1372
Trie_partiel 7 36784 bulle 4.11 1472
Aleatoire 8 94734 insertion 7.30 1996
Aleatoire 8 94734 fusion 0.18 17500
Aleatoire 8 94734 rapide 0.16 1976
Aleatoire 8 94734 bulle 32.41 2004
Trie 8 94734 insertion 0.12 1992
Trie 8 94734 fusion 0.17 17488
Trie 8 94734 rapide 19.87 7868
Trie 8 94734 bulle 14.00 1928
Trie_inverse 8 94734 insertion 14.37 1916
Trie_inverse 8 94734 fusion 0.18 17512
Trie_inverse 8 94734 rapide 10.80 5944
Trie_inverse 8 94734 bulle 22.49 1976
Trie_partiel 8 94734 insertion 5.21 1992
Trie_partiel 8 94734 fusion 0.14 17560
Trie_partiel 8 94734 rapide 0.13 1892
Trie_partiel 8 94734 bulle 27.76 1976
Aleatoire 9 2216 insertion 0.00 1324
Aleatoire 9 2216 fusion 0.00 1608
Aleatoire 9 2216 rapide 9.58 5404
Aleatoire 9 2216 bulle 21.31 1672
Trie 9 2216 insertion 0.00 1288
Trie 9 2216 fusion 0.00 1628
Trie 9 2216 rapide 0.01 1460
Trie 9 2216 bulle 0.01 1288
Trie_inverse 9 2216 insertion 0.01 1348
Trie_inverse 9 2216 fusion 0.00 1680
Trie_inverse 9 2216 rapide 0.00 1460
Trie_inverse 9 2216 bulle 0.01 1348
Trie_partiel 9 2216 insertion 0.00 1404
Trie_partiel 9 2216 fusion 0.00 1688
Trie_partiel 9 2216 rapide 0.00 1324
Trie_partiel 9 2216 bulle 0.00 1332
\ No newline at end of file
#!/bin/bash
echo "sort\tiTest\ttaille\ttri\ttemps\tmem"
for iTest in `seq 1 10`
do
size=$(( `od -An -N4 -tu < /dev/urandom` % 100000))
max=$(( `od -An -N4 -tu < /dev/urandom` % 100000))
for tab in "g" "gt" "gti" "gtp"
do
../tri -$tab $max $size 1 > ../tabs/perf_tab.txt
if [ $tab = "g" ]
then
sort="Aleatoire"
elif [ $tab = "gt" ]
then
sort="Trie"
elif [ $tab = "gti" ]
then
sort="Trie_inverse"
elif [ $tab = "gtp" ]
then
sort="Trie_partiel"
fi
for tri in "insertion" "fusion" "rapide" "bulle"
do
res=`( /usr/bin/time -f "%U\t%M" ../tri --$tri ../tabs/perf_tab.txt > /dev/null ) 2>&1`
echo "$sort\t$iTest\t$size\t$tri\t$res"
done
done
rm ../tabs/perf_tab.txt
done
\ No newline at end of file
This diff is collapsed.
#include "triBulle.h"
void triBulle(long* A, size_t n){
for(int I = n - 2;I >= 0; I--) {
for(int J = 0; J <= I; J++) {
if(A[J + 1] < A[J]) {
int t = A[J + 1];
A[J + 1] = A[J];
A[J] = t;
}
}
}
}
\ No newline at end of file
#ifndef triBulle_h
#define triBulle_h
#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>
#include "../Lib/utils.h"
void triBulle(long* A, size_t n);
#endif
\ No newline at end of file
#include "triFusion.h"
void sousTriFusion(long* A, const size_t p, const size_t r) {
if (p + 1 < r) {
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, const size_t p, const size_t q, const size_t r) {
size_t n1 = q - p;
size_t n2 = r - q;
long* Ag = (long*) malloc(n1 * sizeof(long));
long* Ad = (long*) malloc(n2 * sizeof(long));
size_t cursor = 0;
for (size_t i = p; i < q; i++) {
Ag[cursor++] = A[i];
}
cursor = 0;
for (size_t i = q; i < r; i++) {
Ad[cursor++] = A[i];
}
size_t ind_g = 0;
size_t ind_d = 0;
size_t i = p;
while (i < r) {
if (ind_g == n1) {
A[i] = Ad[ind_d++];
}
else if (ind_d == n2) {
A[i] = Ag[ind_g++];
}
else if (Ag[ind_g] < Ad[ind_d]) {
A[i] = Ag[ind_g++];
}
else {
A[i] = Ad[ind_d++];
}
i++;
}
}
void triFusion(long * A, size_t n){
sousTriFusion(A, 0, n);
}
// --------------------------------------------------------
void sousTriFusionVerbose(long * A, size_t p, size_t r, struct data* d){
if(p<(r-1)){
d->comparison++;
size_t q = (size_t)((p+r)/2);
d->write++;
sousTriFusionVerbose(A, p, q,d);
sousTriFusionVerbose(A, q, r, d);
fusionVerbose(A, p, q, r, d);
}
}
void fusionVerbose(long * A, size_t p, size_t q, size_t r, struct data* d){
size_t n1 = q-p;
d->write++;
size_t n2 = r-q;
d->write++;
long Ad[n2];
memset(Ad, 0, n2);
d->write+=n2;
int j = 0;
for(size_t i = q; i<r; i++){
Ad[j] = A[i];
d->write++;
j++;
d->write++;
}
long Ag[n1];
memset(Ag, 0, n1);
d->write+=n1;
j = 0;
for(size_t i = p; i<q; i++){
Ag[j] = A[i];
d->write++;
j++;
d->write++;
}
size_t indg = 0;
size_t indd = 0;
size_t i = p;
d->write++;
while (i < r){
d->comparison++;
if(indg == n1){
d->comparison++;
A[i] = Ad[indd];
d->write++;
indd++;
d->write++;
}
else if(indd == n2){
d->comparison+=2;
A[i] == Ag[indg];
d->write++;
indg++;
d->write++;
}
else if(Ag[indg] < Ad[indd]){
d->comparison+=3;
A[i] = Ag[indg];
d->write++;
indg++;
d->write++;
}
else{
d->comparison+=4;
A[i] = Ad[indd];
d->write++;
indd++;
d->write++;
}
i++;
d->write++;
}
}
void triFusionVerbose(long * A, size_t n, struct data* d){
sousTriFusionVerbose(A, 0, n, d);
}
\ No newline at end of file
#ifndef triFusion_h
#define triFusion_h
#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>
#include "../Lib/utils.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);
void sousTriFusionVerbose(long * A, size_t p, size_t r, struct data* d);
void fusionVerbose(long * A, size_t p, size_t q, size_t r, struct data* d);
void triFusionVerbose(long * A, size_t n, struct data* d);
#endif
\ No newline at end of file
#include "triInsertion.h"
void triInsertion(long* A, size_t n){
long cle = 0;
for(size_t i = 1; i<n; i++){
cle=A[i];
size_t j = i - 1;
while (j+1 > 0 && A[j] > cle ){
A[j+1] = A[j];
j = j-1;
}
A[j+1] = cle;
}
}
// --------------------------------------------------------
void triInsertionVerbose(long* A, size_t n, struct data* d){
long cle = 0;
d->write++;
for(size_t i = 1; i<n; i++){
cle=A[i];
d->write++;
size_t j = i - 1;
d->write++;
while (j+1 > 0 && A[j] > cle ){
d->comparison+=2;
A[j+1] = A[j];
d->write++;
j = j-1;
d->write++;
}
A[j+1] = cle;
d->write++;
}
}
\ No newline at end of file
#ifndef triInsertion_h
#define triInsertion_h
#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>
#include "../Lib/utils.h"
void triInsertion(long* A, size_t n);
void triInsertionVerbose(long* A, size_t n, struct data* d);
#endif
\ No newline at end of file
#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);
}
// --------------------------------------------------------
void sousTriRapideVerbose(long* A, size_t p, size_t r, struct data* d) {
size_t max = 0; max--;
d->write++;
if(r-1 != max){
d->comparison++;
if (p<(r-1)) {
d->comparison++;
size_t q = partitionVerbose(A, p, r, d);
d->write++;
sousTriRapideVerbose(A, p, q, d);
sousTriRapideVerbose(A, q+1, r, d);
}
}
}
size_t partitionVerbose(long* A, size_t p, size_t r, struct data* d) {
long pivot = A[r-1];
d->write++;
size_t i = p;
d->write++;
for (size_t j = p; j <= r-2; j++) {
if (A[j] <= pivot) {
d->comparison++;
long temp = A[i];
d->write++;
A[i] = A[j];
d->write++;
A[j] = temp;
d->write++;
i++;
d->write++;
}
}
long temp = A[i];
d->write++;
A[i] = A[r-1];
d->write++;
A[r-1] = temp;
d->write++;
return i;
}
void triRapideVerbose(long* A, size_t n, struct data* d) {
sousTriRapideVerbose(A, 0, n, d);
}
\ No newline at end of file
#ifndef triRapide_h
#define triRapide_h
#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>
#include "../Lib/utils.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);
void triRapideVerbose(long* A, size_t n, struct data* d);
size_t partitionVerbose(long* A, size_t p, size_t r, struct data* d);
void sousTriRapideVerbose(long* A, size_t p, size_t r, struct data* d);
#endif
\ No newline at end of file
#include "triRapideInsertion.h"
#include "triInsertion.h"
void sousTriRapideInsertion(long* A, size_t p, size_t r) {
size_t max = 0; max--;
if(r-1 != max){
if (p<(r-1)) {
if(r-p<10){
triInsertion(A, r-p);
}
else
{
size_t q = partition_wInsertion(A, p, r);
sousTriRapideInsertion(A, p, q);
sousTriRapideInsertion(A, q+1, r);
}
}
}
}
size_t partition_wInsertion(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 triRapideInsertion(long* A, size_t n) {
sousTriRapideInsertion(A, 0, n);
}
\ No newline at end of file
#ifndef triRapideInsertion_h
#define triRapideInsertion_h
#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>
#include "../Lib/utils.h"
void triRapideInsertion(long* A, size_t n);
size_t partition_wInsertion(long* A, size_t p, size_t r);
void sousTriRapideInsertion(long* A, size_t p, size_t r) ;
#endif
\ No newline at end of file
all: tri
tri: Lib/main.c Tris/triBulle.o Tris/triInsertion.o Tris/triFusion.o Tris/triRapide.o Tris/triRapideInsertion.o Lib/utils.o
gcc -Wall Lib/main.c Tris/triInsertion.o Tris/triFusion.o Tris/triBulle.o Tris/triRapide.o Tris/triRapideInsertion.o Lib/utils.o -Wall -o tri
insertion: Tris/triInsertion.c Tris/triInsertion.h
gcc -c Tris/triInsertion.c Tris/triInsertion.h -Wall
bulle: Tris/triBulle.c Tris/triBulle.h
gcc -c Tris/triBulle.c Tris/triBulle.h -Wall
fusion: Tris/triFusion.c Tris/triFusion.h
gcc -c Tris/triFusion.c Tris/triFusion.h -Wall
rapide: Tris/triRapide.c Tris/triRapide.h
gcc -c Tris/triRapide.c Tris/triRapide.h -Wall
rapideInsertion: Tris/triRapideInsertion.c Tris/triRapideInsertion.h
gcc -c Tris/triRapideInsertion.c Tris/triRapideInsertion.h -Wall
utils: Lib/utils.c Lib/utils.h
gcc -c Lib/utils.c Lib/utils.h -Wall
clear:
rm Tris/*.o
\ No newline at end of file
# Manuel
Pour utiliser les tris, vous avez besoin de 2 choses:<br>
- Le binaire `tri`<br>
- Un document texte contenant les éléments du tableau, chaque élément est séparé du prochain par un espace et pour finit par un `.`. <br>
Ex : `4 3 11 29 .`<br>
Le binaire demande une option et un fichier, le fichier est du type de ceux définit plus haut, quant aux option il en existe plusieures : <br>
- `-i` ou `--insertion` pour le tri à insertion<br>
- `-f` ou `--fusion` pour le tri à fusion<br>
- `-r` ou `--rapide` pour le tri rapide<br>
- `-a` ou `--all` pour tout les tris disponibles <br>
\ 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 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
This diff is collapsed.
3 6 7 5 3 5 6 2 9 1 .
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