Skip to content
Snippets Groups Projects
Commit a5fc808e authored by Axel's avatar Axel
Browse files

Amélioration procédure affichage et création procédure aléatoire

parent eefa1705
1 merge request!1makefile et autres
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
#include "function.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void afficheTab(int tabAAffiche[], size_t tabTaille){
printf("| ");
for(size_t i=0; i<tabTaille; i++){
printf("%d", tabAAffiche[i]);
if(i==tabTaille-1){
printf("%d", tabAAffiche[i]);
}
else{
printf("%d - ", tabAAffiche[i]);
}
}
printf(" |\n");
}
void genTabAlea(int tabARemplir[], size_t tailleTab) {
int rand_is_seeded = 0;
if(!rand_is_seeded)
{
srand(time(NULL));
rand_is_seeded = 1;
}
for(size_t i=0; i<tailleTab; i++){
tabARemplir[i]=rand()%(10);
}
printf("\n");
}
......@@ -3,3 +3,6 @@
//Procédure d'affichage d'un tableau passé en paramètre
void afficheTab(int tabAAffiche[], size_t tabTaille);
//Remplis le tableau passé en paramètre de valeurs aléatoires
void genTabAlea(int tabARemplir[], size_t tailleTab);
File added
File added
......@@ -8,7 +8,10 @@ int main(int argc, char const *argv[]) {
int tableau[5]={8,4,1,6,5};
afficheTab(tableau, 5);
tri_insertion(tableau,5);
afficheTab(tableau,5);
printf("\n--Test tab aléat--\n");
int tableauBis[20];
genTabAlea(tableauBis,20);
tri_insertion(tableauBis,20);
return 0;
}
File added
......@@ -8,7 +8,7 @@ void tri_insertion(int tabInit[], size_t tailleTab) {
for(size_t i=1; i<tailleTab; i++) {
int cle = tabInit[i];
int j=i-1;
size_t j=i-1;
while(j >= 0 && tabInit[j]>cle) {
tabInit[j+1]=tabInit[j];
......@@ -20,4 +20,5 @@ void tri_insertion(int tabInit[], size_t tailleTab) {
printf("DEBUG: Tableau modifié: \n");
afficheTab(tabInit, tailleTab);
}
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