算法
文章平均质量分 64
seafoodge
这个作者很懒,什么都没留下…
展开
-
选择排序算法的PHP实现
<?phpfunction select_sort($arr){ $len=count($arr); for($i=0; $i<$len-1; $i++){ $min=$i; for ($j = $i+1; $j < $len; $j++) { if($arr[$j]<$arr[$min]){ $min=$j; } } $tmp=$arr[$min];原创 2013-06-07 12:18:13 · 1191 阅读 · 0 评论 -
选择排序、冒泡排序和二分查找C/C++
#include /*蛮力法排序*/void swap(int* a, int* b) //定义交换函数{ *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; }; void selectionSort(int* a, int n) //选择排序算法,复杂度为N的平方{ int min;原创 2012-11-19 22:46:15 · 724 阅读 · 0 评论 -
快速排序算法的C/C++ 实现
#includeint Partiton(int *a,int low,int high){ int pivotkey=a[low]; while(low<high){ while(low=pivotkey) --high; a[low]=a[high]; while(low<high && a[low]<=pivotkey) ++low; a原创 2012-11-19 17:25:14 · 758 阅读 · 0 评论 -
Horspool算法的C++实现
#includeusing namespace std;const int HASH_SIZE=256;int table[HASH_SIZE]; //存放查找文本的信息void ShiftTable(char pattern[]) { int m=strlen(pattern); for(int i=0;i<原创 2012-11-24 10:27:24 · 1536 阅读 · 0 评论 -
插入排序算法的PHP实现
<?php function InsertSort(&$arr){ $Length=count($arr);//尽量不要把count()用在for循环里面,循环每次都要执行这个函数会大大影响效率 for($i=1;$i<$Length-1;$i++){ $temp=$arr[$i]; $j=$i-1; while ($j>=0 &&原创 2012-11-20 17:24:28 · 682 阅读 · 0 评论 -
PHP冒泡排序
<?php/* *冒泡排序属于蛮力法,时间复杂度为N的平方,可以做一下改进:如果对列表比较一遍之后没有交换元素的位置,那么这个表已经排好序了,算法停止*/function bubble_sort($arr){ $len=count($arr);//尽量不要把count()用在for循环里面,循环每次都要执行这个函数会大大影响效率 for($i=0;$i<$len-1;$i++){原创 2013-06-07 02:01:43 · 1480 阅读 · 0 评论