PHP Linked list operation Simple example _php tips

Source: Internet
Author: User

The example of this article tells the PHP list operation. Share to everyone for your reference, specific as follows:

In PHP to run the data structure, the basic is to use the array simulation, but only with the thought.

The problem today is that two linked lists are merged.

Linked list Merge effect chart

Problem Description: A linked list is a template linked list, B chain table length is uncertain, a,b two linked list formed C linked list.

Talk about programming ideas: A linked list is a template linked list, so in the operation completed, the length of the only unchanged. The length of the B-linked list is indeterminate. So you can first of the B-linked list to judge, divided into three steps:

b linked list is not empty
b linked list is not shorter or equal than a list
b linked list is not longer than a chain

Programming is to list as many possibilities as possible. Catch variables, due to the problem requirements, when a linked list and B linked table is equal, directly return B linked list, so do not consider this issue.

 $node = Array ("NameID" => "", "Shoolid" => "", "Depid" => "", "Start" => "", "end
"=>");
* Now the above data, some data exist in a linked list, some exist in B-linked list, if not, with a linked list of data nodes to replace. When I first finished it, I thought of a very painful way to do it, and I used the Arra_diff () function to make the difference with this list.
Then I thought it over carefully.
    *///$data means B-linked list//$time indicates a-linked list//here in order to conserve resources, did not open the third linked list, but in the B-linked list, why choose an uncertain length of the linked list/read you know why. if (empty ($data))//{////
    $data = Array (); foreach ($time as $value) {//require processing of the data in a linked list to form the node pattern we need $array = Array ("NameID" => $value ["id"], "Depid" =&G
      t; $depid, "SchoolID" => $schoolid, "Start" => "", "End" => ""); Array_push ($data, $array); Press the new node into stack} else if (count ($data) <=count ($time))//For length contrast {for ($i =0; $i <count ($time); $i + +)//for loop, not recommended for loop
   Continue to judge dynamically, I am lazy here. {if (Empty ($data [$i])) {//If the data node is empty, the build node $array = Array ("NameID" => $time [$i] ["id"], "Depid" => $de
      PID, "SchoolID" => $schoolid, "Start" => "", "End" => "");
     Array_push ($data, $array); }
   }
}

The above algorithm is simple internship, will be a linked list of data, and B data combination.

For more information about PHP interested readers can view the site topics: "PHP Data structure and algorithm tutorial", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.