分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

php实现链表的基本操作

发布时间:2023-09-06 01:35责任编辑:沈小雨关键词:暂无标签
<?php ?class node{ ???private $value; ???private $next; ???public function __construct($value=0,$next=null){ ???????$this->value=$value; ???????$this->next=$next; ???} ???public function getValue(){ ???????return $this->value; ???} ???public function setValue($value){ ???????return $this->value=$value; ???} ???public function getNext(){ ???????return $this->next; ???} ???public function setNext($next){ ???????return $this->next=$next; ???}}function reverse($node){ ???if (null == $node || null == $node->getNext()) { ???????return $node; ???} ???$reversednode = reverse($node->getNext()); ???$node->getNext()->setNext($node); ???$node->setNext(null); ???return $reversednode;}function insert($node,$value,$position){ ???$tmp=$node; ???for($i=0;$i<$position;$i++){ ???????$tmp=$tmp->getNext(); ???} ???$insertnode=new node($value); ???$insertnode->setNext($tmp->getNext()); ???$tmp->setNext($insertnode);}function delete($node,$position){ ???$tmp=$node; ???for($i=0;$i<$position;$i++){ ???????$tmp=$tmp->getNext(); ???} ???$tmp->setNext($tmp->getNext()->getNext());}echo "<pre>";$node=new node();$tmp=$node;for($i=1;$i<10;$i++){ ???$nextnode=new node($i); ???$tmp->setNext($nextnode); ???$tmp=$nextnode;}print_r($node);$node=reverse($node);insert($node,11,3);delete($node,3);print_r($node);?>

php实现链表的基本操作

原文地址:https://www.cnblogs.com/leedaily/p/8250263.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved