Skip to content
Snippets Groups Projects
Verified Commit d88e5dba authored by orestis.malaspin's avatar orestis.malaspin
Browse files

recherche done

parent e36ef0b3
No related branches found
No related tags found
No related merge requests found
Pipeline #15026 passed
......@@ -526,8 +526,23 @@ sorted_list sorted_list_push(sorted_list list, int val) {
![Extraction d'un élément qui n'est pas le premier.](figs/sorted_list_extract_any.svg){width=70%}
. . .
\footnotesize
```C
// TODO add code
sorted_list sorted_list_extract(sorted_list list, int val) {
element *prec = *crt = list; // needed to glue elements together
while (NULL != crt && val > crt->data) {
prec = crt;
crt = crt->next;
}
if (NULL != crt && prec != crt && crt->data == val) { // glue things together
prec->next = crt->next;
free(crt);
}
return list;
}
```
......@@ -537,14 +552,28 @@ sorted_list sorted_list_push(sorted_list list, int val) {
. . .
![Extraction d'un élément qui est pas le
![Extraction d'un élément qui est le
premier.](figs/sorted_list_extract_first.svg){width=70%}
. . .
\footnotesize
```C
// TODO add code
sorted_list sorted_list_extract(sorted_list list, int val) {
element *prec = *crt = list; // needed to glue elements together
while (NULL != crt && val > crt->data) {
prec = crt;
crt = crt->next;
}
if (NULL != crt && crt->data == val && prec == crt) { // glue things together
list = list->next;
free(crt);
}
return list;
}
```
# L'extraction
3. L'élément à extraire n'est **pas** dans la liste.
......@@ -556,6 +585,23 @@ premier.](figs/sorted_list_extract_first.svg){width=70%}
On retourne la liste inchangée.
. . .
\footnotesize
```C
sorted_list sorted_list_extract(sorted_list list, int val) {
element *prec = *crt = list; // needed to glue elements together
while (NULL != crt && val > crt->data) {
prec = crt;
crt = crt->next;
}
if (NULL == crt || crt->data != val) { // val not present
return list;
}
}
```
# La recherche
# Exercice: recherche sans position
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment