-
-
Save geykel/6b41494935f4daa9b417e5470e219591 to your computer and use it in GitHub Desktop.
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
// 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