tp7 exo4
This commit is contained in:
parent
ba1c439c95
commit
0830136fb8
10
tp7/exo3.c
10
tp7/exo3.c
@ -15,12 +15,10 @@ ilc creer_ilc() { return (ilc){NULL}; }
|
||||
milc *tete_ilc(ilc l) { return l.debut; }
|
||||
milc *suivant_ilc(milc m) { return m.suivant; }
|
||||
void inserer_ilc(ilc *l, milc *m, int x) {
|
||||
milc *parent = l->debut;
|
||||
while (x > 0) {
|
||||
parent = parent->suivant;
|
||||
}
|
||||
m->suivant = parent->suivant;
|
||||
parent->suivant = m;
|
||||
milc* m2 = malloc(sizeof(milc));
|
||||
m2->valeur = x;
|
||||
m2->suivant = m->suivant;
|
||||
m->suivant = m;
|
||||
}
|
||||
void retirer_ilc(ilc *l, milc *m) {
|
||||
if (l->debut == m) {
|
||||
|
||||
59
tp7/exo4.c
Normal file
59
tp7/exo4.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include "exo1.c"
|
||||
|
||||
itr creer_ilc_itr(int estimation_capacite) {
|
||||
return creer_itr(estimation_capacite*2);
|
||||
}
|
||||
void inserer_ilc_itr(itr* t, int indice, int x) {
|
||||
int n = taille_itr(*t);
|
||||
if (taille_itr(*t) == 0) {
|
||||
append_itr(t, x);
|
||||
} else {
|
||||
int tmp;
|
||||
while (indice < n) {
|
||||
tmp = acces_itr(*t, indice);
|
||||
modif_itr(*t, indice, x);
|
||||
indice++;
|
||||
x = tmp;
|
||||
}
|
||||
append_itr(t, tmp);
|
||||
}
|
||||
}
|
||||
void retirer_ilc_itr(itr* t, int indice) {
|
||||
int x = pop_itr(t);
|
||||
for (int i = taille_itr(*t)-1; i >= indice; i--) {
|
||||
int tmp = acces_itr(*t, i);
|
||||
modif_itr(*t, i, tmp);
|
||||
x = tmp;
|
||||
}
|
||||
}
|
||||
int acceder_ilc_itr(itr t, int indice) {
|
||||
return acces_itr(t, indice);
|
||||
}
|
||||
void modifier_ilc_itr(itr t, int indice, int x) {
|
||||
modif_itr(t, indice, x);
|
||||
}
|
||||
void inserer_tete_ilc_itr(itr* t, int x) {
|
||||
inserer_ilc_itr(t, 0, x);
|
||||
}
|
||||
int retirer_tete_ilc_itr(itr* t) {
|
||||
int x = acces_itr(*t, 0);
|
||||
retirer_ilc_itr(t, 0);
|
||||
return x;
|
||||
}
|
||||
void inserer_fond_ilc_itr(itr* t, int x) {
|
||||
if (taille_itr(*t) == 0) {
|
||||
append_itr(t, x);
|
||||
} else {
|
||||
inserer_ilc_itr(t, taille_itr(*t)-1, x);
|
||||
}
|
||||
}
|
||||
int retirer_fond_ilc_itr(itr* t) {
|
||||
int x;
|
||||
if (taille_itr(*t) == 0) {
|
||||
x = pop_itr(t);
|
||||
} else {
|
||||
x = acces_itr(*t, taille_itr(*t)-1);
|
||||
retirer_ilc_itr(t, taille_itr(*t)-1);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user