/** * Beispiel aus * * - Algorithmen und Datenstrukturen für Dummies * - von Andreas Gogol-Döring und Thomas Letschert * - Verlag Wiley-VCH; Oktober 2019 * - Kapitel 3, Daten und ihre Struktur * * @author A. Gogol-Döring, Th. Letschert */ import Foundation struct AuD_03_04_FListADT { /* Summentypen können in Swift als Emums realisiert werden */ enum FList { case Nil indirect case Cons (head: Int, tail:FList) } static func FLst(n: Int) -> FList { func F(x: Int) -> Int { return (x == 0) ? 1 : x * F(x: x-1) } var l: FList = .Nil for i in 0 ... n { l = .Cons(head: F(x: i), tail: l) } return l } static func run() { print(FLst(n: 5)) } }