perl

推荐列表 站点导航

当前位置:首页 > 脚本编程 > perl >

Perl归并有序数组算法

来源:网络  作者:网友投稿  发布时间:2021-01-14 19:12
题目2年前面baidu的时候问的,看起来很简朴,写起来照旧容易错。当年太菜,写的少。此刻写出来不错也不容易。...

归并两个有序数组, 这个二分法插入是不特别开发空间的, 题目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

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Perl归并有序数组算法

2021-01-14 编辑:网友投稿

归并两个有序数组, 这个二分法插入是不特别开发空间的, 题目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

相关文章

风云图片

推荐阅读

返回perl频道首页