2015-01-21 09:23:00 +01:00
|
|
|
# Les files
|
|
|
|
Le principe est celui des files d'attentes : premier arrivé, premier sorti.
|
|
|
|
|
|
|
|
## Primitives
|
|
|
|
### Déclaration
|
|
|
|
```python
|
|
|
|
f = creer_pile()
|
|
|
|
bool : file_vide(f)
|
|
|
|
bool : file_pleine(f)
|
|
|
|
ajout_fin_file()
|
|
|
|
elt = debut_file()
|
|
|
|
retirer_debut_file()
|
|
|
|
```
|
|
|
|
```
|
|
|
|
Maillon struct (
|
|
|
|
valeur : INT
|
|
|
|
suivant : SAME)
|
|
|
|
|
|
|
|
File struct (
|
|
|
|
debut : Maillon
|
|
|
|
Fin : Maillon)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Définition (listes)
|
|
|
|
```python
|
|
|
|
def creer_file():
|
|
|
|
file = File(debut=None, fin=None)
|
|
|
|
return file
|
|
|
|
|
|
|
|
def file_vide(file):
|
|
|
|
return file.debut is None
|
|
|
|
|
|
|
|
def file_pleine(file):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def ajout_fin_file(file, elt):
|
|
|
|
mail = Maillon(valeur=elt, suivant=None)
|
2015-01-21 09:43:46 +01:00
|
|
|
if file.fin:
|
2015-01-21 09:23:00 +01:00
|
|
|
file.fin.suivant = mail
|
|
|
|
else:
|
|
|
|
file.debut = mail
|
|
|
|
file.fin = mail
|
|
|
|
|
|
|
|
def debut_file(file):
|
|
|
|
return file.debut.valeur
|
|
|
|
|
|
|
|
def retirer_debut_file(file):
|
|
|
|
mail = file.debut
|
|
|
|
file.debut = file.debut.suivant
|
|
|
|
if not file.debut:
|
|
|
|
file.fin = None
|
|
|
|
free(mail)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Définition (tableaux)
|
2015-01-21 09:43:46 +01:00
|
|
|
`TODO : Implémenter ça pour le 1/02`
|
|
|
|
|
|
|
|
## Exercices
|
|
|
|
### Exercice 1
|
|
|
|
Écrire un algo qui affiche les éléments d'une file en la conservant.
|
|
|
|
|
|
|
|
```python
|
|
|
|
def affiche_file(f):
|
|
|
|
f_temp = creer_file()
|
|
|
|
|
|
|
|
while !file_vide(f):
|
|
|
|
print(debut_file(f))
|
|
|
|
ajouter_fin_file(f_temp, debut_file(f))
|
|
|
|
retirer_debut_file(f)
|
|
|
|
|
|
|
|
f = f_temp
|
|
|
|
return f
|
|
|
|
```
|