Initiation à la programmation ENSAE 1A

ecrit_2007_rattrapage2.tex

File: ecrit_2007_rattrapage2.tex, line 32


s = 0
for i in range (1,101) :
   s = i + 100-i+1
s = s / 2

File: ecrit_2007_rattrapage2.tex, line 56


def fusion (l1,l2) :
  i,j = 0,0
  r = []

  while len (r) < len (l1) + len (l2) :
    if i < len (l1) and (j >= len (l2) or l1[i] < l2 [j]) :
      r.append (l1 [i])
      i += 1
    else :
      r.append (l2 [j])
      j += 1
      
  return r

File: ecrit_2007_rattrapage2.tex, line 101


class Noeud : 
  def __init__ (self) :
    self.n1 = None
    self.n2 = None

root = Noeud ()
root.n1 = Noeud ()
root.n2 = Noeud ()
root.n1.n1 = Noeud ()
root.n1.n2 = root

File: ecrit_2007_rattrapage2.tex, line 128


def compte_noeud (self, l = []) :
    if self not in l :
        l.append (self)
        if self.n1 != None : self.n1.compte_noeud (l)
        if self.n2 != None : self.n2.compte_noeud (l)
    return len (l)

File: ecrit_2007_rattrapage2.tex, line 150


%