Skip to content
Snippets Groups Projects
Commit e03ea21e authored by GOSSA JULIEN's avatar GOSSA JULIEN
Browse files

Merge branch '2020' into 'master'

2020

See merge request !2
parents 8963c3c0 10e59583
Branches 2020
1 merge request!22020
......@@ -38,23 +38,17 @@ Suite des commandes, ou script, à exécuter pour produire les données.
### Temps d'exécution
| Opération | Tableau | Liste chaînée | |
|----------------------|---------------------------|---------------------------|---------------------------|
| Insertion | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Accès | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
![plot](prealable.png)
### Consommation mémoire
| Opération | Tableau | Liste chaînée | |
|----------------------|---------------------------|---------------------------|---------------------------|
| Insertion | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| Accès | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
| | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) | ![plot](path/to/plot.png) |
![plot](prealable-mem.png)
### Analyse des résultats préalables
Explications précises et succinctes des résultats préalables.
La mémoire se comporte exactement pareil sur les 4 versions.
Les temps d'exécutions dépendent essentiellement de l'affichage des valeurs du tableau.
La version 2 de recherche semble un peu plus rapide.
### Discussion des résultats préalables
......
/**
Recherche d'un entier alétoire dans un tableau de valeurs aléatoires
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_VALEUR 15
int *generer_tableau(long long unsigned int n)
{
int *tableau = malloc(n*sizeof(int));
long long unsigned int i;
for (i=0; i<n; i++) {
tableau[i] = rand()%MAX_VALEUR;
}
return tableau;
}
void afficher_tableau(int *tableau, long long unsigned int n)
{
long long unsigned int i;
for (i=0; i<n; i++) {
printf("%d ",tableau[i]);
}
printf("\n");
}
long long unsigned int rechercher(int *tableau, long long unsigned int n, int valeur)
{
long long unsigned int i;
long long unsigned int trouve = -1;
for (i=0; i<n; i++) {
if (tableau[i] == valeur) {
trouve=i;
}
}
return trouve;
}
int main(int argc, char *argv[])
{
int *tableau;
int taille, valeur;
char trouve;
if (argc<2) {
printf("%s: opérande manquant\n",argv[0]);
printf("Recherche une valeur aléatoire dans un tableau d'entier aléatoire de taille n\n");
printf("Affiche le tableau et renvoie 1 si la valeur est trouvée, 0 sinon\n");
exit(1);
printf("Usage: %s taille [graine]\n",argv[0]);
}
unsigned int graine;
if (argc>2) {
graine = atoi(argv[2]);
} else {
graine = time(NULL);
}
srand(graine);
taille = strtoull(argv[1], (char **) NULL, 10);
valeur = rand()%MAX_VALEUR;
tableau = generer_tableau(taille);
afficher_tableau(tableau,taille);
trouve = rechercher(tableau, taille, valeur);
printf("Valeur %d trouvée: %u\n",valeur, trouve);
}
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