search sort
来源:互联网 发布:高斯金字塔算法 matlab 编辑:程序博客网 时间:2024/06/06 17:30
sub Seq_Search{
my($array,$elem)=@_;
$n=@{$array};
${$array}[$n]=$elem;#监视哨
for($i=0;${$array}[$i]!=$elem;$i++);
return($i<$n);
}#ASL=n+1
my($array,$elem)=@_;
$n=@{$array};
${$array}[$n]=$elem;#监视哨
for($i=0;${$array}[$i]!=$elem;$i++);
return($i<$n);
}#ASL=n+1
sub Binary_Search{
my($array,$elem)=@_;
$high=@{$array};
$low=0;
while($low<$high){
$mid=($low+$high)/2;
if(${$array}[$mid]==$elem){
return 1
}
elsif(${$array}[$mid]<$elem){
$low=$mid+1;
}
else{
$high=$mid;
}
}
return 0;
}
sub Insert_Sort{
my($array)=@_;
for ($i=1;$i<@{$array};$i++)
{
$temp = ${$array}[$i];
$j=$i-1;
while ($j>-1 and $temp<${$array}[$j])
{
${$array}[$j+1]=${$array}[$j];
$j--;
}
${$array}[$j+1]=$temp;
}
}
sub Bubble_Sort{#递增
my($array)=@_;
for ($j=0;$j<@{$array}-1;$j++){
for ($i=0;$i<@{$array}-1-$j;$i++)
{
if(${$array}[$i] > ${$array}[$i+1])
{
$temp=${$array}[$i];
${$array}[$i]=${$array}[$i+1];
${$array}[$i+1]=$temp;
}
}
}
}
my($array,$elem)=@_;
$high=@{$array};
$low=0;
while($low<$high){
$mid=($low+$high)/2;
if(${$array}[$mid]==$elem){
return 1
}
elsif(${$array}[$mid]<$elem){
$low=$mid+1;
}
else{
$high=$mid;
}
}
return 0;
}
sub Insert_Sort{
my($array)=@_;
for ($i=1;$i<@{$array};$i++)
{
$temp = ${$array}[$i];
$j=$i-1;
while ($j>-1 and $temp<${$array}[$j])
{
${$array}[$j+1]=${$array}[$j];
$j--;
}
${$array}[$j+1]=$temp;
}
}
sub Bubble_Sort{#递增
my($array)=@_;
for ($j=0;$j<@{$array}-1;$j++){
for ($i=0;$i<@{$array}-1-$j;$i++)
{
if(${$array}[$i] > ${$array}[$i+1])
{
$temp=${$array}[$i];
${$array}[$i]=${$array}[$i+1];
${$array}[$i+1]=$temp;
}
}
}
}
sub Quick_Sort
阅读全文
0 0
- search sort
- search - binary search/sort tree
- hibernate search sort()
- KNOW: Sort & Search
- search and sort
- search and sort [2]
- Search and Sort
- pyes Search 的sort用法
- Sort and Search in C and C++
- merge sort and binary search recursive version
- STL 之search,search_n,sort,binary_search
- STL 之search,search_n,sort,binary_search
- 搜索接口-排序(Search API-sort)
- Algorithms Review: Divide and Conquer(Binary Search & Merge Sort)
- C++ Binary Search Sort 二分查找排序算法
- sort
- Sort
- sort
- 51Nod-1228-序列求和
- Kafka的安装与简单测试
- 文章标题
- MySQL 常用索引及创建方法
- HDOJ2102 深搜DFS解法+剪枝优化 入门题
- search sort
- 微信小程序获取open-gid和群名称
- CSS3 选择器——基本选择器
- CSS3 选择器——属性选择器
- MyBatis绑定错误--BindingException:Invalid bound statement (not found)
- CSS3 选择器——伪类选择器
- PHP ,与. 字符串拼接效率比较及原理
- python 字符编码转换详解
- 高级网络管理之bond与team