Background:
I was trying to figure out something else and started using xdebug+webgrind two days ago. The feeling is very convenient, but still just a beginner, many features have not yet been understood. Without the direction to do something, then continue to lay the groundwork, today began to look to find this piece.
Business:
Sequential lookup-A sequential lookup is the exact location of the same number as a given keyword in a known no (or ordered) Order queue. The principle is that the keyword is compared to the number in the queue from the last one, until it finds the same number as the given keyword, and its disadvantage is inefficiency.
The concept is very clear, the shortcomings are easy to see, the direct sticker code (I am here as an example of the order table).
<?PHP/** * Linear table Node class * is used to store the values of a number set and to implement sequential lookups of linear tables **/classrectype{/** * Store numeric values * * @var int*/ Public $val; /** * Store additional Information * * @var mix*/ Public $other; Public function__construct ($val,$other=NULL) { $this->val =$val; $this->other =$other; }}/** Search for the position of a keyword in a given number of strings * * @param array of given number of arrays * @param int Key number to find * * return int return position if not found return false*/functionSeq_search ($search _val,$search _key){ $r=Array(); Init_rectype ($r,$search _val,$search _key); $num=Count($r); while($r[$num--]->val! =$search _key); if($num<0) { return false; } Else { return $num+1; }}/** * establish linear table of sequential structure * * @param array of linear table arrays container * @param array linear table cell values collection * @param int key number to find * * return*/functionInit_rectype (&$r,$search _val,$search _key){ $r[0] =NewRecType$search _key); if(Is_array($search _val)) { foreach($search _val as $val) { $r[] =NewRecType$val); } } Else { Exit(' Unrecognized search type '); } return ;}//Test$search=Array(5,3,48,646,489,123,465468,12,54,6,2);$search _key= 12;$result= Seq_search ($search,$search _key);if($result!==false){ Echo $search _key, ' in the sequence of the first ',$result, ' bit ';
12 in the 8th bit of the sequence}Else{ Echo $search _key, ' does not exist in the sequence ';}?>
There is also a lookout for R [0], which was also mentioned in the direct insert sort that was written earlier, and did not understand the effect of its terminating sign, but here it is perfectly clear.
Algorithm exercise--sequential lookup