Skip to content

Instantly share code, notes, and snippets.

@geykel
Created May 2, 2017 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geykel/6b41494935f4daa9b417e5470e219591 to your computer and use it in GitHub Desktop.
Save geykel/6b41494935f4daa9b417e5470e219591 to your computer and use it in GitHub Desktop.
// 1
struct A {
func mensajeA() -> String {
return "Soy de tipo A"
}
}
// 2
struct B {
func mensajeB() -> String {
return "Soy de tipo B"
}
}
// 3
struct Pila<T> {
// 4
private var elementos = [T]()
// 5
mutating func poner(_ elemento: T) {
elementos.append(elemento)
}
// 6
mutating func extraer() -> T {
return elementos.removeLast()
}
}
// 7
var pilaA = Pila<A>()
var a1 = A()
pilaA.poner(a1)
print(pilaA.extraer().mensajeA())
// 8
var pilaB = Pila<B>()
var b1 = B()
pilaB.poner(b1)
print(pilaB.extraer().mensajeB())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment