<?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>戈壁滩上的狗尾巴花 &#187; 算法</title>
	<atom:link href="http://liguoliang.com/tag/%e7%ae%97%e6%b3%95/feed/" rel="self" type="application/rss+xml" />
	<link>http://liguoliang.com</link>
	<description>戈壁滩上盛开的一坨狗尾巴花</description>
	<lastBuildDate>Fri, 10 Sep 2010 13:46:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ActionScript实现顺序查找,二分查找</title>
		<link>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e9%a1%ba%e5%ba%8f%e6%9f%a5%e6%89%be%e4%ba%8c%e5%88%86%e6%9f%a5%e6%89%be/</link>
		<comments>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e9%a1%ba%e5%ba%8f%e6%9f%a5%e6%89%be%e4%ba%8c%e5%88%86%e6%9f%a5%e6%89%be/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 08:48:12 +0000</pubDate>
		<dc:creator>老李</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[查找]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/10/261/</guid>
		<description><![CDATA[<p>写的比较潦草,欢迎指正….批评是我前进的动力&#8230;&#8230;</p>
顺序查找实现 Sequential Search

	/**
	 * 顺序查找实现 Sequential Search
	 */
	 public static function sequentialSearch(k:int,]]></description>
			<content:encoded><![CDATA[<p>写的比较潦草,欢迎指正….批评是我前进的动力&#8230;&#8230;</p>
<h3>顺序查找实现 Sequential Search</h3>
<pre class="java" name="code">
	/**
	 * 顺序查找实现 Sequential Search
	 */
	 public static function sequentialSearch(k:int, a:Array):int {
	 	var index:int = -1;
	 	for(var i:int = 0; i<a.length; i++) {
	 		if(a[i] == k) {
	 			index = i;
	 		}
	 	}
	 	return index;
	 }
</pre>
<h3>二分查找实现</h3>
<pre class="java" name="code">
/**
	 * 二分查找实现
	 */
	public static function binarySearch(k:int, a:Array):int {
		var startIndex:int = 0;
		var endIndex:int = a.length - 1;
		var midIndex:int;
		var index:int = -1;

		while(startIndex <= endIndex) {
			midIndex = int((startIndex + endIndex)/2);
			if(k > a[midIndex]) {
				startIndex = midIndex + 1;
			}else {
				endIndex = midIndex - 1;
			}
			if(k == a[midIndex]) {
				index = midIndex;
			}
		}//end of while
		return index;
	}//end of function binarySearch
</pre>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/actionscript%e5%ae%9e%e7%8e%b0%e9%a1%ba%e5%ba%8f%e6%9f%a5%e6%89%be%e4%ba%8c%e5%88%86%e6%9f%a5%e6%89%be/feed/</wfw:commentRss>
		<slash:comments>1</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>老李</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[<p>上学时数据结构就一直没学好, 死皮赖脸连抄带蒙, 补考时才考过. 早知道现如今脑子不够使, 那时候一定好好学&#8230;.</p>
<p>排序的算法比较多,大概可分为:    <br />* 插入排序     <br />* 冒泡排序     <br />* 选择排序     <br />* 快速排序     <br />* 堆排序     <br />* 归并排序     <br />* 基</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>
]]></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>
