this article illustrates how PHP combines two sorted lists. Share to you for your reference, as follows:

input two monotonically increasing output list, the two list after the synthesis of the list, of course we need after the synthesis of monotone nondecreasing rules list.

solves the simple merge sort of

. Since the two sequences are already increasing, it is possible to take the smaller parts of the two sequences each time.

 < code; PHP /*class ListNode{var $val? VaR; $next = NULL; function __construct ($x) {$this-> Val = $x;}}*/ function Merge ($pHead1, $pHead2) {if ($pHead1 = = NULL) return $pHead2; if ($pHead2 = = NULL) return $pHead1; $reHead = new (ListNode) if ($pHead1-> Val; < $pHead2-> VAL) {$reHead = $pHead1; $pHead1 = $pHead1-> $reHead = next;}else{$pHead2; $pHead2 = $pHead2-> next;} $p ($pHead1& = $reHead; while; & $pHead2) {if ($pHead1-> val < = $pHead2-> VAL) {$p-> next = $pHead1; $pHead1 = $pHead1-> $p = next; $p-> next;} else{$p-> next = $pHead2; $pHead2 = $pHead2-> next = $p; $p -> next;}} if ($pHead1! = NULL) {$p-> next = $pHead1;} if ($pHead2! = NULL) next = $p-> $pHead2; return $reHead;} 

more PHP on the relevant content of interested readers can see the special station: " PHP data the structure and algorithm of ," php ", summarizes the algorithm program design "php string (string) " PHP array (Array) technique," PHP common traversal algorithm with and" PHP

" math skills summary

hope the PHP program designed to help to everyone.

This paper fixed link:http://www.script-home.com/php-implementation-of-merging-two-sorting-chain-tables.html | Script Home | +Copy Link

Article reprint please specify:PHP implementation of merging two sorting chain tables | Script Home

You may also be interested in these articles!