<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Developer Papercuts &#187; Scala</title>
	<atom:link href="http://www.vogella.de/blog/tag/scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vogella.de/blog</link>
	<description>Tips around Eclipse and Android programming</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quicksort in Scala</title>
		<link>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/</link>
		<comments>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 05:57:47 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1283</guid>
		<description><![CDATA[Scala  allows to define very short and precise the intension of the programmer. To demonstrate this I use Quicksort as an Example.

The following is an implementation of quicksort in Scala. 



And a little test




To learn more about Scala check out this introduction tutorial: Scala development with Eclipse 

Update: this example is similar to ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vogella.de/articles/Scala/article.html">Scala </a> allows to define very short and precise the intension of the programmer. To demonstrate this I use <a href="http://www.vogella.de/articles/JavaAlgorithmsQuicksort/article.html">Quicksort </a>as an Example.</p>
<p>The following is an implementation of quicksort in Scala. </p>
<pre class="brush: scala; title: ; notranslate">

package de.vogella.scala.quicksort

/* Quicksort in Scala */
class Quicksort {
	def sort(a:Array[Int]): Array[Int] =
		if (a.length &lt; 2) a
		else {
			val pivot = a(a.length / 2)
			sort (a filter (pivot&gt;)) ++ (a filter (pivot == )) ++
				sort (a filter(pivot &lt;))
		}
}
</pre>
<p>And a little test</p>
<pre class="brush: scala; title: ; notranslate">

package de.vogella.scala.quicksort

object Test {
  def main(args: Array[String]) = {
    val quicksort = new Quicksort
	val a = Array(5, 3, 2, 2, 1, 1, 9, 39 ,219)
	quicksort.sort(a).foreach(n=&gt; (print(n), print (&quot; &quot; )))

  }
}
</pre>
<p>To learn more about Scala check out this introduction tutorial: <a href="http://www.vogella.de/articles/Scala/article.html">Scala development with Eclipse </a></p>
<p><strong>Update</strong>: this example is similar to the quicksort example from the excellent online <a href="http://www.scala-lang.org/docu/files/ScalaByExample.pdf">Scala by Example book</a>. Caution: The link is a pdf document.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.vogella.de/blog/?flattrss_redirect&amp;id=1283&amp;md5=4aa6cececf6742983e33fc239160a346" title="Flattr" target="_blank"><img src="http://www.vogella.de/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

