<?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>Li Guoliang &#187; 排序</title>
	<atom:link href="http://liguoliang.com/tag/%e6%8e%92%e5%ba%8f/feed/" rel="self" type="application/rss+xml" />
	<link>http://liguoliang.com</link>
	<description>ActionScript Flex Java JEE PHP...</description>
	<lastBuildDate>Mon, 21 May 2012 17:04:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>HashSet &#8211; 覆盖equals, hashCode</title>
		<link>http://liguoliang.com/2009/hashset-%e8%a6%86%e7%9b%96equals-hashcode/</link>
		<comments>http://liguoliang.com/2009/hashset-%e8%a6%86%e7%9b%96equals-hashcode/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 09:57:07 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[HashSet]]></category>
		<category><![CDATA[哈希码]]></category>
		<category><![CDATA[排序]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2009/01/704/</guid>
		<description><![CDATA[覆盖equlas 和hashCode两函数, 获得更自由的控制.<p class='read-more'><a href='http://liguoliang.com/2009/hashset-%e8%a6%86%e7%9b%96equals-hashcode/'></a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>覆盖equlas 和hashCode两函数, 获得更自由的控制.</p>
<p>某set, 存一些Email, 如下:   <br /><a href="mailto:e1@abc.com">e1@abc.com</a>&#160; <br />e1@Abc.com     <br />e1@ABc.com     <br />e2@ABC.com     <br />e3@abC.com </p>
<p>很明显, 一共3个不同邮箱,</p>
<p>现在创建了Email类, 需要将这帮Email放入一个HashSet中, 当然,    </p>
<p>e1@abc.com    <br />e1@abc.com     <br />e1@Abc.com     <br />e1@ABc.com     <br />这几个是一模一样的, 都是<a href="mailto:e1@abc.com">e1@abc.com</a></p>
<p>因此需要重写Email的equlas 和hashCode两个函数, 以便保证Set的唯一性.</p>
<p>代码:</p>
<pre class="java" name="code">	//重写equals
	public boolean equals(Object obj) {
		if(this == obj) {
			return true;
		}

		final Email email = (Email)obj;

		if(this.pB.equals(email.pB) &amp;&amp; this.pA.equalsIgnoreCase(email.pA)) {
			return true;
		}else {
			return false;
		}
	}

	//重写hashCode
	public int hashCode() {
		int result;
		result = pB.hashCode() + pA.toLowerCase().hashCode();
		return result;
	}</pre>
<p>在Email外部将这开始提到的这帮email建立为Email类, 并加入到某Set中, </p>
<p>注意: 为了保证HashSet正常工作, 要求当两个对象用equals()方法比较结果为True时, 起hashCode也必须相同, 因此覆盖了equals之后 必须覆盖hashCode.</p>
<p>结果是该Set的size为3 &#8211; 达到要求….</p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2009/hashset-%e8%a6%86%e7%9b%96equals-hashcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript实现插入排序[直接插入排序 Insertion Sort],交互排序排序[单向双向冒泡排序 Bubble Sort]</title>
		<link>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f%e7%9b%b4%e6%8e%a5%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f-insertion-sort%e4%ba%a4%e4%ba%92%e6%8e%92%e5%ba%8f%e6%8e%92%e5%ba%8f/</link>
		<comments>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f%e7%9b%b4%e6%8e%a5%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f-insertion-sort%e4%ba%a4%e4%ba%92%e6%8e%92%e5%ba%8f%e6%8e%92%e5%ba%8f/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 08:41:10 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[排序]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/10/260/</guid>
		<description><![CDATA[上学时数据结构就一直没学好, 死皮赖脸连抄带蒙, 补考时才考过. 早知道现如今脑子不够使, 那时候一定好好学&#8230;.
排序的算法比较多,大概可分为:    * 插入排序     * 冒泡排序     * 选择排序     * 快速排序     * 堆排序     * 归并排序     * 基<p class='read-more'><a href='http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f%e7%9b%b4%e6%8e%a5%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f-insertion-sort%e4%ba%a4%e4%ba%92%e6%8e%92%e5%ba%8f%e6%8e%92%e5%ba%8f/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>上学时数据结构就一直没学好, 死皮赖脸连抄带蒙, 补考时才考过. 早知道现如今脑子不够使, 那时候一定好好学&#8230;.</p>
<p>排序的算法比较多,大概可分为:    <br />* 插入排序     <br />* 冒泡排序     <br />* 选择排序     <br />* 快速排序     <br />* 堆排序     <br />* 归并排序     <br />* 基数排序     <br />* 希尔排序     <br />在这我就找俩最简单的练练手先, 写的不一定对, 欢迎指正, 批评才是我前进的动力&#8230;</p>
<h3>直接插入排序&#160; Insertion Sort</h3>
<pre class="java" name="code">
	 }
	/**
	 * 插入排序[直接插入排序 Insertion Sort]
	 */
	 public static function insertionSort(arrayToBeSorted:Array):void {
	 	for(var i:int = 0; i<arrayToBeSorted.length; i++) {
		 	var temp:int = arrayToBeSorted[i];
		 	for(var j:int = i; j>0; j--) {
		 		if(arrayToBeSorted[j-1]>arrayToBeSorted[i]) {
		 			arrayToBeSorted[j] = arrayToBeSorted[j-1];
		 		}else {
		 			break;
		 		}
		 		trace(j);
		 	}
		 	arrayToBeSorted[j] = temp;
	 	}
	 	trace(arrayToBeSorted);
	 }
</pre>
<h3>交互排序[冒泡排序 Bubble Sort]</h3>
<pre class="java" name="code">
 /**
	 * 交互排序[冒泡排序 Bubble Sort]
	 */
	 public static function bubbleSort(arraytoBeSorted:Array):void {
	 	var startIndex:int = 0;
	 	var tempIndex:int;
	 	for(var j:int = arraytoBeSorted.length - 1; j>0; j--) {
		 	for(var i:int = arraytoBeSorted.length - 1; i>startIndex; i--) {
		 		if(arraytoBeSorted[i-1]>arraytoBeSorted[i]) {
		 			//swap(arraytoBeSorted[i], arraytoBeSorted[i-1]);
		 			var temp:int = arraytoBeSorted[i];
		 			arraytoBeSorted[i] = arraytoBeSorted[i-1];
		 			arraytoBeSorted[i-1] = temp;
		 			tempIndex = i;
		 		}
		 	}//end of for
	 		startIndex = tempIndex;
	 		trace("StartIndex: " + startIndex);
	 	trace("冒泡法排序结果: " + arraytoBeSorted);
		 }//end of for
	 }
</pre>
<h4>双向冒泡:</h4>
<pre class="java" name="code">
 /**
	 * 交互排序[双向冒泡]
	 */
	 public static function doubleDirectionBubbleSort(arrayToBeSorted:Array):void {
	 	var j:int;
	 	var k:int;
	 	var tempIndex:int = arrayToBeSorted.length;

	 	var startIndex:int = 0;
	 	var endIndex:int = arrayToBeSorted.length - 1;

	 	var change:Boolean = true;
	 	while(startIndex<endIndex &#038;&#038; change) {
		 	trace("双向冒泡排序前: " + arrayToBeSorted);
	 		for(j = endIndex; j>startIndex; j--) {
	 			change = false;
	 			if(arrayToBeSorted[j]<arrayToBeSorted[j-1]) {
	 				var temp:int = arrayToBeSorted[j];
	 				arrayToBeSorted[j] = arrayToBeSorted[j-1];
	 				arrayToBeSorted[j-1] = temp;
	 				change = true;
	 			}
	 			trace("轻的上浮: " + arrayToBeSorted +" Changed: " + change.toString() + " StrtIndex: " + j + " EndIndex:" + endIndex);
	 			tempIndex = j;
	 		} //end of for
	 		startIndex = tempIndex;
	 		for(k = startIndex; k<endIndex; k++) {
	 			change = false;
	 			if(arrayToBeSorted[k-1]>arrayToBeSorted[k]) {
	 				var temp:int = arrayToBeSorted[k];
	 				arrayToBeSorted[k] = arrayToBeSorted[k-1];
	 				arrayToBeSorted[k-1] = temp;
	 				change = true;
	 			}
	 			tempIndex = k;
	 			trace("重的下沉: " + arrayToBeSorted +" Changed: " + change.toString() + " StrtIndex: " + startIndex + " EndIndex:" + k);
	 		}//end of for
	 		endIndex = tempIndex;
	 		trace("startIndex: " + startIndex + " endIndex: " + endIndex);
	 		trace("双向冒泡排序后: " + arrayToBeSorted);
	 	}//end of while
	 }//end of function
</pre>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f%e7%9b%b4%e6%8e%a5%e6%8f%92%e5%85%a5%e6%8e%92%e5%ba%8f-insertion-sort%e4%ba%a4%e4%ba%92%e6%8e%92%e5%ba%8f%e6%8e%92%e5%ba%8f/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

