Discussione trasformare pseudocodice ricorsivo in iterativo

giupardeb

Utente Silver
15 Novembre 2016
118
30
15
90
Buona sera a tutti, ho il seguente pseudocodice:

Codice:
RS(n,c)
Input: c: a sequence with n elements
Output: A random permutation on c

begin
  if n <= 1 then
      return c
  if n = 2 then
      if rand-bit = 1 then
          return (c_2 , c_1)
      else
          return (c_1,c_2)
  Let A_0 and A_1 be two empty arrays
  for i = 1 to n do
      add ci into A_rand-bit
  return RS(|A_0|, A_0), RS(|A_1|, A_1)

vorrei la rispettiva versione iterativa, ma non sto riuscendo a venirne a capo..qualcuno può darmi una mano?
Grazie mille anticipamente!
 
Codice:
begin
  if n <= 1 then
      return c
  if n = 2 then
      if rand-bit = 1 then
          return (c_2 , c_1)
      else
          return (c_1,c_2)
  Let A_0 and A_1 be two empty arrays
  for i = 1 to n do
      add ci into A_rand-bit
  return A_0 concat A_1