/**
la (3, 5, 8, 11)
lb (2, 6, 8, 9, 11, 15)
Merge into lc and arrange in order.
Use PHP to implement it, you cannot use functions such as sort! ! ! !
**/
class union {
var $lista = array();
var $listb = array();
var $listc = array();
Function getlenght($arr) { //Get the table length
return count($arr);
}
Function getelement($arr, $n) { //Get the nth element in the table and return
return $e = $arr[$n] ? $arr[$n] : '';
}
Function listinsert($arr, $e) { //Insert element at the end of the table
$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 the 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);
?>
http://www.bkjia.com/PHPjc/922887.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/922887.htmlTechArticlephp implements the method of merging two tables into a new table and arranging them in order. The specific implementation method is as follows: The code is as follows: ?php /** la (3, 5, 8, 11) lb (2, 6, 8, 9, 11, 15) are combined into lc, with...