Readme.org et un exemple
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
1) Avec la représentation du cours d'une file par une liste [3, *,
|
||||
*, A, B, C] où l[0] est l'indice du premier élément de la file,
|
||||
les opérations enfile et défile ont des complexités en $O(1)$. La
|
||||
fonction peek consiste à renvoyer l[l[0]] si l[0] > 0, et None sinon.
|
||||
2)
|
||||
#+begin_src python
|
||||
def hamming(n):
|
||||
f2, f3, f5 = nouvelle_file(), nouvelle_file(), nouvelle_file()
|
||||
l = [1]
|
||||
enfile(f2, 2);enfile(f3, 3);enfile(f5, 5)
|
||||
while True:
|
||||
k2, k3, k5 = peek(f2), peek(f3), peek(f5)
|
||||
m = min(k2, k3, k5)
|
||||
if k2 == m: defile(f2)
|
||||
if k3 == m: defile(f3)
|
||||
if k5 == m: defile(f5)
|
||||
enfile(f2, 2*m); enfile(f3, 3*m); enfile(f5, 5*m)
|
||||
if m<n:
|
||||
l)append(m)
|
||||
else:
|
||||
break
|
||||
return l
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user