Perl归并有序数组算法
归并两个有序数组, 这个二分法插入是不特别开发空间的, 题目2年前面baidu的时候问的。
8);my $start = 0;my $end = @a -1 ;for my $t (@b){print Tracking $t \n;my $cur;#binary searchdo{$cur = int(($start+$end)/2);$end = $cur if($t$a[$cur]);$start = $cur if($t$a[$cur]);if($t == $a[$cur]){$end = $cur +1;$start = $cur;}}while($end-$start 1);#assign the proper postion$cur = $end;#if the value is larger than the last element in current array,3,5,此刻写出来不错也不容易, 4最简朴的虽然是新建一个数组然后一个个往内里放,7);my @b = (1, then append thelement to the last ;if($t$a[$end]){$cur = $end+1;}#move elements after current postion with distance 1for(my $i = @a-1; $i = $cur; $i--){$a[$i+1] = $a[$i];}$a[$cur] = $t;$start = $cur;$end = @a-1;print -----------@a---------------\n;} ,感受巨大度还可以更低,6,2,可是弄起来会贫苦。
看起来很简朴,写起来照旧容易错,当年太菜,写的少,4,再想想 my @a = (1,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/perl/12626.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
关于Perl里的真值假值具体
时间:2021-01-14
-
试了很多方法总是有这样
时间:2021-01-14
-
perl rrdtool绘制网络流量图
时间:2020-12-26
-
如何将perl里的大小写自己
时间:2020-12-26
-
关于Perl里的真值假值详细
时间:2020-12-26
热门文章
-
如何将perl里的大小写自己进行函数转换
时间:2020-12-26
-
perl rrdtool绘制网络流量图
时间:2020-12-26
-
关于Perl里的真值假值具体先容
时间:2021-01-14
-
关于Perl里的真值假值详细介绍
时间:2020-12-26
-
试了很多方法总是有这样那样的问题产生
时间:2021-01-14
