Sha256: 08f885b781151280975a9b327c3641d686d25f9cc9ee3bf10e7eed7159f0db30

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 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: [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

41 entries across 41 versions & 1 rubygems

Version Path
trackler-2.0.6.15 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.14 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.13 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.12 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.11 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.10 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.9 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.8 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.7 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.6 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.5 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.4 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.3 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.2 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.1 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.6.0 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.5.18 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.5.17 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.5.16 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift
trackler-2.0.5.15 tracks/swift/exercises/simple-linked-list/SimpleLinkedListExample.swift