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...