The implementation methods are as follows:
code is as follows: <?php
/**
La (3,5,8,11)
lb (2,6,8,9,11,15)
merged into LC, arranged in order.
is implemented in PHP, and you can't use a function like sort!!!!
**/
Class Union {
var $lista = array ();
var $listb = array ();
var $listc = array ();
function Getlenght ($arr) {//Get table length
return count ($arr);
}
function GetElement ($arr, $n) {//Get the nth element in the table, return
return $e = $arr [$n]? $arr [$n]: ';
}
function Listinsert ($arr, $e) {//At the end of the table insert element
$arr [] = $e;
return $arr;
}
}
$phpig = new Union ();
$lista = $phpig->lista = Array (3, 5, 8, 11);
$listb = $phpig->listb = Array (2, 6, 8, 9, 11, 15);
$LISTC = $phpig->listc;
$lena = $phpig->getlenght ($lista); Get Table Size
$lenb = $phpig->getlenght ($LISTB);
$i = $j = 0;
while ($i < $lena && $j < $lenb) {
$ea = $phpig->getelement ($lista, $i);
$eb = $phpig->getelement ($LISTB, $j);
if ($ea <= $eb) {
$LISTC = $phpig->listinsert ($LISTC, $ea);
+ + $i;
} else {
$LISTC = $phpig->listinsert ($LISTC, $eb);
+ + $j;
}
}
while ($i < $lena) {
$ea = $phpig->getelement ($lista, $i);
$LISTC = $phpig->listinsert ($LISTC, $ea);
+ + $i;
}
while ($j < $lenb) {
$eb = $phpig->getelement ($LISTB, $j);
$LISTC = $phpig->listinsert ($LISTC, $eb);
+ + $j;
}
Print_r ($LISTC);
?>