Created
March 22, 2013 02:00
-
-
Save jagbolanos/5218394 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
def sumarListas(l:List[Int], m:List[Int]) : List[Int] = (l, m) match { | |
case (Nil, Nil) => Nil | |
case (Nil, y :: ys) => y :: sumarListas(Nil, ys) | |
case (y :: ys, Nil) => y :: sumarListas(ys, Nil) | |
case (x :: xs, y :: ys) => (x+y) :: sumarListas(xs, ys) | |
} | |
def extraerImpares(l:List[Int]) : List[Int] = l match { | |
case Nil => Nil | |
case x :: xs => if ( x % 2 != 0) x :: extraerImpares(xs) else extraerImpares(xs) | |
} | |
def menores(n:Int, l:List[Int]) : List[Int] = l match { | |
case Nil => Nil | |
case x :: xs => if (x < n) x :: menores(n, xs) else menores(n, xs) | |
} | |
def mayores(n:Int, l:List[Int]) : List[Int] = l match { | |
case Nil => Nil | |
case x :: xs => if (x > n) x :: mayores(n, xs) else mayores(n, xs) | |
} | |
def quicksort(l:List[Int]) : List[Int] = l match { | |
case Nil => Nil | |
case x :: xs => quicksort(menores(x, xs)) ++ List(x) ++ quicksort(mayores(x,xs)) | |
} | |
class PersonaMadre { | |
def nombre() : String = "Nada" | |
} | |
class Persona(nombre:String, edad:Int) extends PersonaMadre { | |
override def toString : String = nombre | |
override def nombre() : String = nombre | |
} | |
abstract class Expresion { | |
def evaluar : Int | |
} | |
case class Valor(n:Int) extends Expresion { | |
override def evaluar : Int = n | |
} | |
case class Suma(izq: Expresion, der: Expresion) extends Expresion { | |
override def evaluar : Int = izq.evaluar + der.evaluar | |
} | |
case class Mult(izq: Expresion, der: Expresion) extends Expresion { | |
override def evaluar : Int = izq.evaluar * der.evaluar | |
} | |
def evaluar(e: Expresion) : Int = e match { | |
case Valor(x) => x | |
case Suma(x,y) => evaluar(x) + evaluar(y) | |
case Mult(x,y) => evaluar(x) * evaluar(y) | |
} | |
def prefijo(e: Expresion) : String = e match { | |
case Valor(x) => x + " " | |
case Suma(x, y) => "+ " + prefijo (x) + prefijo(y) | |
case Mult(x, y) => "* " + prefijo (x) + prefijo(y) | |
} | |
def postfijo(e: Expresion) : String = e match { | |
case Valor(x) => x + " " | |
case Suma(x, y) => postfijo (x) + postfijo(y) + "+ " | |
case Mult(x, y) => postfijo (x) + postfijo(y) + "* " | |
} | |
case class NodoBinario(v:Int, izq:NodoBinario, der:NodoBinario) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment