av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

php語(yǔ)言

php如何快速實(shí)現(xiàn)兩表合并并有序排列

時(shí)間:2025-05-21 12:35:03 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

php如何快速實(shí)現(xiàn)兩表合并并有序排列

  如何快速實(shí)現(xiàn)兩表合并并有序排列呢?下面是小編給大家提供的代碼實(shí)例,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。

  具體實(shí)現(xiàn)方法如下:

  代碼如下:

  <?php

  /**

  la (3,5,8,11)

  lb(2,6,8,9,11,15)

  合并為lc,有序排列。

  用php實(shí)現(xiàn),不能用sort之類的函數(shù)!。。

  **/

  class union {

  var $lista = array();

  var $listb = array();

  var $listc = array();

  function getlenght($arr) { //獲得表長(zhǎng)度

  return count($arr);

  }

  function getelement($arr, $n) { //獲取表中第n個(gè)元素,返回

  return $e = $arr[$n] ? $arr[$n] : '';

  }

  function listinsert($arr, $e) { //表末尾插入元素

  $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); //取得表大小

  $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);

  ?>

【php如何快速實(shí)現(xiàn)兩表合并并有序排列】相關(guān)文章:

php如何實(shí)現(xiàn)快速排序04-03

如何運(yùn)用PHP實(shí)現(xiàn)字符串逆序排列02-17

PHP中多態(tài)如何實(shí)現(xiàn)05-06

PHP如何遞歸實(shí)現(xiàn)json類06-27

如何實(shí)現(xiàn)PHP圖片裁剪與縮放07-13

如何用PHP實(shí)現(xiàn)找回密碼02-03

PHP弱類型變量是如何實(shí)現(xiàn)的05-31

php如何實(shí)現(xiàn)驗(yàn)證碼06-13

PHP中如何實(shí)現(xiàn)crontab代碼05-30