Sha256: bb89634003d64c46380e983a274ab7c27b6fe725a578cccab12ee9cda2e225e2
Contents?: true
Size: 1.12 KB
Versions: 30
Compression:
Stored size: 1.12 KB
Contents
private extension Array { func reversedCustom() -> Array { return reversed() } } class Element<T> { var value: T? = nil var next: Element? = nil init() { } init(_ value: T, _ next: Element?) { self.value = value self.next = next } func toArray () -> [T] { return toA(self) } private var countArray: Array<T> = [] @discardableResult private func toA(_ input: Element, _ tempArray: Array<T> = []) -> [T] { if tempArray.isEmpty && input.value != nil { countArray.append(input.value!) } if input.next != nil && input.next!.value != nil { countArray.append(input.next!.value!) toA(input.next!, countArray) } return countArray } class func fromArray(_ input: [T]) -> Element { var tempElement = Element<T>() for each in Array(input.reversedCustom()) { tempElement = Element(each, tempElement) } return tempElement } func reverseElements() -> Element { return Element.fromArray(Array(toArray().reversedCustom())) } }
Version data entries
30 entries across 30 versions & 1 rubygems