Skip to content

Instantly share code, notes, and snippets.

@eneko eneko/List.swift
Last active Jul 29, 2018

What would you like to do?
Linked List in Swift
/// A list is either empty or it is composed of a first element (head)
/// and a tail, which is a list itself.
/// See
class List<T> {
var value: T
var nextItem: List<T>?
convenience init?(_ values: T...) {
init?(_ values: [T]) {
guard let first = values.first else {
return nil
value = first
nextItem = List(Array(values.suffix(from: 1)))

This comment has been minimized.

Copy link

commented Feb 4, 2018

(Swift 4 warning for line 9) Parameters may not have the 'var' specifier. I like your 99 problems website btw.


This comment has been minimized.

Copy link
Owner Author

commented Feb 19, 2018

Hey Scott, thank you for your feedback. It is updated to Swift 4 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.