Skip to content
Snippets Groups Projects
Commit 633094cf authored by Elio Malfara's avatar Elio Malfara
Browse files

Ajout du tri insertion

parent 15fd8827
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
void triInsertion(long* A, size_t n){
for(size_t i = 1; i < n; i ++){
long cle = A[i];
size_t j = i - 1;
while(j + 1 > j && A[j] > cle){ // ici on veut regarder tant que j >= 0
A[j + 1] = A[j];
j = j - 1;
}
A[j + 1] = cle;
}
}
void printTab(long* A,size_t n){
printf("{");
for(size_t i = 0;i < n;i++){
if(i != 0){
printf(",");
}
printf("%ld",A[i]);
}
printf("}\n");
}
int main(int argc, char* argv[]){
long* A = malloc((argc-1)*sizeof(long));
for(size_t i = 0;i < argc-1;i++){
A[i] = atol(argv[i+1]);
}
printf("Tableau d'entrée: ");
printTab(A,argc-1);
triInsertion(A,argc-1);
printf("Tableau de sortie: ");
printTab(A,argc-1);
free(A);
}
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