<?php
function sort_arr($a,$b) {
$temp = array();
while ($a&&$b) {
if($a['0']<$b['0']) {
$temp[] = array_shift($a);
} else {
$temp[] = array_shift($b);
}
}
if(!emptyempty($a)) { $temp = array_merge($temp, $a); }
if(!emptyempty($b)) { $temp = array_merge($temp, $b); }
return $temp;
}
$a = array(1,2,3,4,5,6);
$b = array(2,3,4,10,10,10,10);
sort_arr($a, $b);
?>
Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 3 [4] => 3 [5] => 4 [6] => 4 [7] => 5 [8] => 6 [9] => 10 [10] => 10 [11] => 10 [12] => 10 )
def fib(a,b):
len_a = len(a)
c = []
while len(a) and len(b):
if a[0] > b[0]:
c.append(b.pop(0))
else:
c.append(a.pop(0))
if len(a):
c = c+a
if len(b):
c = c+b
i=0
while i<len(c):
print(c[i])
i = i+1
a = [1,2,3,4,5]
b = [2,3,4,5,6,7,8,9]
fib(a,b)
#include <stdio.h>;
int *sort(int a[], int b[], int a_len, int b_len) {
int *temp = malloc(a_len+b_len);
int i=0; //标注a数组
int j=0; //标注b数组
int m=0; //标注新数组
while (i<a_len&&j<b_len) { //重新排序 if(a[i]<b[j]) {
temp[m++] = b[j++];
} else {
temp[m++] = a[i++];
}
}
//将剩余的数字放在新数组后面(剩余的肯定是前面的数字大)
if(i<a_len) {
for (; i<a_len; i++) {
temp[m++] = a[i];
}
}
if(j<b_len) {
for (; j<b_len; j++) {
temp[m++] = b[j];
}
}
return temp;
}
int main(int argc, const char * argv[]) {
int a[4] = {2,3,11,89};
int b[6] = {4,6,9,10,22,55};
int a_len = sizeof(a) / sizeof(a[0]);
int b_len = sizeof(b) / sizeof(b[0]);
int *c = sort(a, b, a_len, b_len);
int y = 0;
for (; y<a_len+b_len; y++) {
printf("%d ", c[y]);
}
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有