This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func add(a: Int, b: Int) -> Int{ | |
return a + b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func add(a: Int, b: Int) -> Int{ | |
return a + b | |
} | |
func add(a: Double, b: Double) -> Double{ | |
return a + b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func add<T: Numeric>(a: T, b: T) -> T{ | |
return a + b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func swapTwoInts(_ a: inout Int, _ b: inout Int) { | |
let temporaryA = a | |
a = b | |
b = temporaryA | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func swapTwoInts(_ a: inout Int, _ b: inout Int) { | |
let temporaryA = a | |
a = b | |
b = temporaryA | |
} | |
func swapTwoDoubles(_ a: inout Double, _ b: inout Double) { | |
let temporaryA = a | |
a = b | |
b = temporaryA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func swapTwoValues<T>(_ a: inout T, _ b: inout T) { | |
let temporaryA = a | |
a = b | |
b = temporaryA | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node{ | |
var content: Int | |
var next: Node | |
init(content: Int, next: Node){ | |
self.content = content | |
self.next = next | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node<T>{ | |
var content: T | |
var next: Node? | |
init(content: T, next: Node?){ | |
self.content = content | |
self.next = next | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node<T>{ | |
var content: T | |
var next: Node? | |
init(content: T, next: Node?){ | |
self.content = content | |
self.next = next | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> { | |
var i = 0 | |
return AnyIterator { | |
let next = withUnsafeBytes(of: &i) { $0.load(as: T.self) } | |
if next.hashValue != i { return nil } | |
i += 1 | |
return next | |
} |