Sha256: c9101ba7dbe4ce12613b16ba93511a532f9858f7ea01e7310c08303ef23aa969
Contents?: true
Size: 1.1 KB
Versions: 325
Compression:
Stored size: 1.1 KB
Contents
private extension Array { func reversedCustom() -> Array { return reversed() } } class Element<T> { var value: T? var next: Element? init() { } init(_ value: T, _ next: Element?) { self.value = value self.next = next } func toArray () -> [T] { return toA(self) } private var countArray: [T] = [] @discardableResult private func toA(_ input: Element, _ tempArray: [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
325 entries across 325 versions & 1 rubygems