<?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>phill84.org &#187; Public Static Void</title>
	<atom:link href="http://phill84.org/tag/public-static-void/feed/" rel="self" type="application/rss+xml" />
	<link>http://phill84.org</link>
	<description>System.out.print</description>
	<lastBuildDate>Sat, 26 Mar 2011 10:21:26 +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>One-way QuickSort implemented in Java</title>
		<link>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/</link>
		<comments>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 07:21:08 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[Int Tmp]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Java Codes]]></category>
		<category><![CDATA[Partition]]></category>
		<category><![CDATA[Pivots]]></category>
		<category><![CDATA[Public Static Void]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[Quicksort Java]]></category>

		<guid isPermaLink="false">http://phill84.org/?p=70</guid>
		<description><![CDATA[The codes might be not optimized, and the first elements of all arrays are chosen as the pivots, which will cause a tremendous slow-down when the array is sorted already. 1 2 3 4 5 6 7 8 9 10 &#8230; <a href="http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The codes might be not optimized, and the first elements of all arrays are chosen as the pivots, which will cause a tremendous slow-down when the array is sorted already.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> swap<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ar, <span style="color: #000066; font-weight: bold;">int</span> a, <span style="color: #000066; font-weight: bold;">int</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">int</span> tmp <span style="color: #339933;">=</span> ar<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	ar<span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ar<span style="color: #009900;">&#91;</span>b<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	ar<span style="color: #009900;">&#91;</span>b<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> tmp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> partition<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a, <span style="color: #000066; font-weight: bold;">int</span> left, <span style="color: #000066; font-weight: bold;">int</span> right<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">int</span> pivot<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> m<span style="color: #339933;">=</span>left<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>left<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>right<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>pivot<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			m<span style="color: #339933;">++;</span>
			swap<span style="color: #009900;">&#40;</span>a, i, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
	<span style="color: #009900;">&#125;</span>
	swap<span style="color: #009900;">&#40;</span>a, left, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> m<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> quicksort<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> a, <span style="color: #000066; font-weight: bold;">int</span> left, <span style="color: #000066; font-weight: bold;">int</span> right<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>left<span style="color: #339933;">&gt;=</span>right<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> pivotIndex <span style="color: #339933;">=</span> partition<span style="color: #009900;">&#40;</span>a, left, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a, left, pivotIndex<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a, pivotIndex<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2008/06/one-way-quicksort-implemented-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

