Skip to content

Commit

Permalink
edit Scala post
Browse files Browse the repository at this point in the history
usando ``` para resaltar codigo en el post
  • Loading branch information
pazthor committed Aug 7, 2014
1 parent a2b4680 commit 1436f5f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions _posts/2014-05-23-Post-sort-scala.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Empezaré con una caracteristica propia de los lenguajes funcionales (como *Hask

Ahora abajo les muestro el algoritmo del **QuickSort** implementado en Java.

{% highlight java %}


```
package de.vogella.algorithms.sort.quicksort;
public class Quicksort {
Expand Down Expand Up @@ -64,10 +66,9 @@ public class Quicksort {
}
{% endhighlight %}

```
Este es la implementacion en Scala.
{% highlight scala %}

```
def sort(xs: Array[Int]) {
def swap(i: Int, j: Int) {
val t = xs(i); xs(i) = xs(j); xs(j) = t
Expand All @@ -90,12 +91,11 @@ def sort(xs: Array[Int]) {
sort1(0, xs.length - 1)
}

{% endhighlight %}
```

¿Iguales no? ahora les muestro el algoritmo **QuickSort** implementado en Scala pero con estilo *funcional*.


```
{% highlight scala %}
def sort(xs: Array[Int]): Array[Int] = {
if (xs.length <= 1) xs
Expand All @@ -107,8 +107,7 @@ def sort(xs: Array[Int]): Array[Int] = {
sort(xs filter (pivot <)))
}
}

{% endhighlight %}
```


El algoritmo implementado de manera funcional captura la esencia del algoritmo QuickSort de manera consisa:
Expand Down

0 comments on commit 1436f5f

Please sign in to comment.