Php implements single-chain table, php implements single-chain _ PHP Tutorial

Source: Internet
Author: User
Php implements a single-chain table, and php implements a single-chain table. Php implements single-chain table, php implements single-chain? Php *** single-chain table ** classDemo {private $ id; public $ name; public $ next; publicfunction _ construct ($ id, $ name) {$ this php implements single-chain table, php single-chain
 Id = $ id; $ this-> name = $ name;} static public function show ($ head) {$ cur = $ head; while ($ cur-> next) {echo $ cur-> next-> id, '###', $ cur-> next-> name ,'
'; $ Cur = $ cur-> next;} echo' ';} // End-insertion method static public function push ($ head, $ node) {$ cur = $ head; while (NULL! = $ Cur-> next) {$ cur = $ cur-> next;} $ cur-> next = $ node; return $ head;} static public function insert ($ head, $ node) {$ cur = $ head; while (NULL! = $ Cur-> next) {if ($ cur-> next-> id> $ node-> id) {break;} $ cur = $ cur-> next ;} $ node-> next = $ cur-> next; $ cur-> next = $ node; return $ head;} static public function edit ($ head, $ node) {$ cur = $ head; while (NULL! = $ Cur-> next) {if ($ cur-> next-> id = $ node-> id) {break;} $ cur = $ cur-> next ;} $ cur-> next-> name = $ node-> name; return $ head;} static public function pop ($ head, $ node) {$ cur = $ head; while (NULL! = $ Cur-> next) {if ($ cur-> next ==$ node) {break;} $ cur = $ cur-> next ;} $ cur-> next = $ node-> next; return $ head ;}$ team = new Demo (); $ node1 = new Demo (1, 'tangsanzang '); demo: push ($ team, $ node1); $ node1-> name = 'tangsan'; Demo: show ($ team); // Demo :: show ($ team); $ node2 = new Demo (2, 'Sun wukong'); Demo: insert ($ team, $ node2); // Demo :: show ($ team); $ node3 = new Demo (5, 'white-Dragon Marat'); Demo: push ($ team, $ node3); // Demo :: show ($ team); $ node4 = new Demo (3, 'Pig bag'); Demo: insert ($ team, $ node4); // Demo :: show ($ team); $ node5 = new Demo (4, 'sa Monk '); Demo: insert ($ team, $ node5); // Demo :: show ($ team); $ node4-> name = 'pig goken'; // reference the php object, so Demo: edit is not necessary // unset ($ node4 ); // $ node4 = new Demo (3, 'Pig goken'); // Demo: edit ($ team, $ node4); Demo: pop ($ team, $ node1); Demo: show ($ team );

Why? Php/*** single-chain table */class Demo {private $ id; public $ name; public $ next; public function _ construct ($ id = '', $ name = '') {$ this...

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.