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

FINISH: Tri insertion

parent ef299bde
No related merge requests found
...@@ -27,13 +27,13 @@ int main(int argc, char **argv){ ...@@ -27,13 +27,13 @@ int main(int argc, char **argv){
printf("n:%d\n", n); printf("n:%d\n", n);
printf("Base : "); printf("Base : ");
for(int i = 0; i<n; i++){ for(int i = 0; i<n; i++){
// printf("i:%d cont:%ld\n", i, tab[i]); printf("%ld-", tab[i]);
} }
printf("\n"); printf("\n");
triInsertion(tab, n); triInsertion(tab, n);
printf("Insertion : "); printf("Insertion : ");
for(int i = 0; i<n; i++){ for(int i = 0; i<n; i++){
// printf("i:%d cont:%ld\n", i, tab[i]); printf("%ld-", tab[i]);
} }
printf("\n"); printf("\n");
free(tab); free(tab);
......
...@@ -5,7 +5,7 @@ echo -e "iTest\ttaille\ttri\ttemps\tmem" ...@@ -5,7 +5,7 @@ echo -e "iTest\ttaille\ttri\ttemps\tmem"
for iTest in `seq 1 2` for iTest in `seq 1 2`
do do
size=$(( `od -An -N4 -tu < /dev/urandom` % 1000000)) size=$(( `od -An -N4 -tu < /dev/urandom` % 1000000))
max=$(( `od -An -N4 -tu < /dev/urandom` % 100000)) max=$(( `od -An -N4 -tu < /dev/urandom` % 1000))
./tri -g $max $size 1>tabs/perf_tab.txt ./tri -g $max $size 1>tabs/perf_tab.txt
#cat tabs/perf_tab.txt #cat tabs/perf_tab.txt
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
void triInsertion(long* A, size_t n){ void triInsertion(long* A, size_t n){
long cle = 0; long cle = 0;
size_t max = 0; 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;
while (j != max && A[j] > cle ){ while (j+1 > 0 && A[j] > cle ){
A[j+1] = A[j]; A[j+1] = A[j];
j = j-1; j = j-1;
} }
...@@ -14,18 +13,19 @@ void triInsertion(long* A, size_t n){ ...@@ -14,18 +13,19 @@ void triInsertion(long* A, size_t n){
} }
} }
// -------------------------------------------------------- // --------------------------------------------------------
void triInsertionVerbose(long* A, size_t n, struct data* d){ void triInsertionVerbose(long* A, size_t n, struct data* d){
long cle = 0; long cle = 0;
size_t max = 0; max--;
d->write++; d->write++;
for(size_t i = 1; i<n; i++){ for(size_t i = 1; i<n; i++){
cle=A[i]; cle=A[i];
d->write++; d->write++;
size_t j = i - 1; size_t j = i - 1;
d->write++; d->write++;
while (j != max && A[j] > cle ){ while (j+1 > 0 && A[j] > cle ){
d->comparison+=2; d->comparison+=2;
A[j+1] = A[j]; A[j+1] = A[j];
d->write++; d->write++;
......
No preview for this file type
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