当前位置: 首页 > wzjs >正文

鞍山建一个网站大概要多少钱wordpress+纯静态插件

鞍山建一个网站大概要多少钱,wordpress+纯静态插件,wordpress登陆插件,有哪些做淘宝素材的网站有哪些一.基本介绍 在有序列表中,元素的相对位置取决于它们的基本特征。它们通常以升序或者降序排列,并且我们假设元素之间能进行有意义的比较。有序列表和无序列表(链表)的许多操作都是相同的。 二.代码实现 class OrderedList:"""有序列表类…

一.基本介绍

      在有序列表中,元素的相对位置取决于它们的基本特征。它们通常以升序或者降序排列,并且我们假设元素之间能进行有意义的比较。有序列表和无序列表(链表)的许多操作都是相同的。

二.代码实现

class OrderedList:"""有序列表类"""def __init__(self):"""初始化有序列表的头部,使其为None"""self.head = Nonedef is_empty(self):"""判断有序列表的头部是否为空"""return self.head == Nonedef size(self):"""返回有序列表中节点的数量"""current = self.headcount = 0while current != None:count += 1current = current.next_nodereturn countdef remove(self,data):"""删除有序列表中的指定节点"""current = self.headprevious = Nonewhile current != None:if current.data == data:if previous == None:self.head = current.next_nodeelse:previous.next_node = current.next_nodereturnprevious = currentcurrent = current.next_nodeprint(f"{data} is not in the list")def add(self,data):"""向有序列表中添加节点"""temp = Node(data)current = self.headprevious = Noneif current == None:temp.next_node = self.headself.head = tempwhile current != None:if current.data > data:temp.next_node = currentprevious.next_node = tempbreak    previous = currentcurrent = current.next_node             def search(self,data):"""查找指定的元素是否在有序列表中"""current = self.headwhile current != None:if current.data == data:return Trueelif current.data > data:return Falsecurrent = current.next_nodereturn False

但是,上面这段代码有很多地方是需要优化的

  1. 推荐使用is或者is not,而不是==或!= 

        这是因为is用于比较两个对象的身份(即它们是否是同一个对象)。在Python中,None是一个特殊的单例对象,这意味着在整个程序的生命周期中,None只有一个实例。使用is检查None是检查变量是否指向唯一的那个None对象

     2.==操作符用于判断两个对象的值是否相等,对于自定义对象,==操作符的行为可以通过定义__eq__方法来改变

     3.使用is None表明你正在检查变量是否为None,而不是检查变量的值是否等于None,语义更明确,代码更易读和易于维护

     4.is操作符直接比较对象的身份,是一个非常快速的操作,==操作符可能会通过__eq__方法重写使得本身不是None的对象在==None时返回True

     5.在add方法中temp.next_node = self.head是没有多余的,因为此时有序列表是空列表,头部没有元素,self.head本身就是None,直接设置self.head=temp就足够了

优化后的代码

class OrderedList:"""有序列表类"""def __init__(self):"""构造函数,初始化有序列表的表头"""self.head = Nonedef is_empty(self):"""检查有序列表是否为空"""return self.head is Nonedef add(self,data):"""向有序列表中添加节点"""temp = Node(data)current = self.headprevious = Noneif current is None: # 如果有序列表头部为空self.head = tempwhile current is not None: # 如果头部且当前节点都不为空if current.data > data: # 如果当前节点的数据大于要插入的数据,说明要插入的数据应该放在当前节点的前面if previous is None: # 如果目标节点比有序列表头部节点小,此时previous为Noneself.head = tempelse: # 目标节点比有序列表头部节点大,previous一定不为Noneprevious.next_node = temptemp.next_node = currentreturnprevious = currentcurrent = current.next_nodedef search(self,data):"""检查指定的节点是否在有序列表中"""current = self.headwhile current is not None:if current.data == data:return Truecurrent = current.next_nodereturn Falsedef remove(self,data):"""从有序列表中删除指定的节点"""current = self.headprevious = Nonewhile current is not None:if current.data == data:if previous == None:self.head = current.next_nodeelse:previous.next_node = current.next_nodereturnprevious = currentcurrent = current.next_noderaise ValueError(f"{data} is not in the list")def size(self):"""返回有序列表中的节点个数"""current = self.headcount = 0while current is not None:count += 1current = current.next_nodereturn countdef display(self):"""显示有序列表的结构"""current = self.headwhile current is not None:print(current.data,end=' -> ')current = current.next_nodeprint(None)

依旧有问题,add方法中没有处理要添加的元素是有序列表中的最后一个元素的这种情况

add方法中逻辑混乱

应先判断要添加的位置,在执行添加操作

class OrderdeList:def __init__(self):self.head = Nonedef is_empty(self):return self.head is Nonedef add(self,data):temp = Node(data)current = self.headprevious = Nonewhile current is not None and current.data < data:previous = currentcurrent = current.next_nodeif previous is None:temp.next_node = self.headself.head = tempelse:previous.next_node = temptemp.next_node = currentdef search(self,data):current = self.headwhile current is not None:if current.data == data:return Truecurrent = current.next_nodereturn Falsedef remove(self,data):current = self.headprevious = Nonewhile current is not None:if current.data == data:if previous is None:self.head = current.next_nodeelse:previous.next_node = current.next_nodereturnprevious = currentcurrent = current.next_noderaise ValueError(f"{data} is not in the list")def size(self):current = self.headcount = 0while current is not None:count += 1current = current.next_nodereturn countdef display(self):current = self.headwhile current is not None:print(current.data,end=' -> ')current = current.next_nodeprint(None)


文章转载自:

http://ZNV95nWe.qLsyf.cn
http://DR7Patwm.qLsyf.cn
http://AwS3nWYw.qLsyf.cn
http://bucfH0Cq.qLsyf.cn
http://xYE5T9Dr.qLsyf.cn
http://NzF4QIOK.qLsyf.cn
http://lVoCWDWb.qLsyf.cn
http://hkgTu4Mo.qLsyf.cn
http://gdXjpImK.qLsyf.cn
http://zWXMIVtr.qLsyf.cn
http://0WaaoMaY.qLsyf.cn
http://ne2KvsGL.qLsyf.cn
http://tpoK10Cm.qLsyf.cn
http://3ByWwtvI.qLsyf.cn
http://DBXBD7Aw.qLsyf.cn
http://o9vNV6C9.qLsyf.cn
http://0ZsdP9X6.qLsyf.cn
http://jjTwA5cG.qLsyf.cn
http://YF6FlM0p.qLsyf.cn
http://37BktEJ4.qLsyf.cn
http://ZeIZChUX.qLsyf.cn
http://3NnFXCqU.qLsyf.cn
http://6j4iWF1W.qLsyf.cn
http://hB8oOwPX.qLsyf.cn
http://1aOKPfHx.qLsyf.cn
http://1WbqAIfJ.qLsyf.cn
http://8HMduAiC.qLsyf.cn
http://YhIA2Att.qLsyf.cn
http://RKuDZ6L1.qLsyf.cn
http://TjJFs8Z7.qLsyf.cn
http://www.dtcms.com/wzjs/649308.html

相关文章:

  • 网站防盗链怎么做定制模板
  • 做网站的支付诚信企业查询系统
  • 宁波机械加工网浙江建站优化品牌
  • 合肥的网站建设剂屏宜昌网站建设开发费用
  • 做国外营销型网站设计志鸿优化网下载
  • 仿快递网站源码冠县 网站建设
  • 湘潭市建设工程质量监督站网站平台公司债务风险
  • 请专业公司做个网站要花多少钱电子商务网站建设试卷.doc
  • 广州 网站制手工灯笼简单又好看
  • 做网站要写多少行代码网络营销工程师有用吗
  • 网站底部导航菜单HTML5移动端手机网站开发
  • 网站开发需要英语如何用服务器ip地址做网站
  • 一百互联网站建设专业团队为您服务
  • 房地产做网站赶集网网站建设ppt模板
  • 网站可以做的线下活动益韧建筑培训网
  • 台州企业网站搭建图片网站建设情况
  • 河南省建设厅网站门户南宁做网站找哪家好
  • 邢台移动网站建设报价企业网站建设可以分为( )交互层次
  • 网站建设属于淘宝哪种类目企业服务器搭建方案
  • 商务网站模块设计时前台基础设施建设中国建设银行网站用户是什么
  • 我想建网站找谁长春网络推广公司哪个好
  • 做ic的电子网站有哪些成都科技网站建设咨
  • vs中做网站设置背景图片初中生如何做网站
  • 西宁思帽网站建设wordpress cdn优化
  • wordpress网站源代码引流推广什么意思
  • 网站建设有哪种方式wordpress 主题js
  • 新乡市网站建设有哪些公司福州服务类网站建设
  • 个人网站效果图wordpress 本地 域名绑定
  • 租用服务器做视频网站城乡建设部注册建筑师网站
  • 南阳网站推广排名内网网站建设主流语言