Python语言例题集(008)

#!/usr/bin/python3

#建立链表类和遍历此链表

class Node():

def init (self,data=None):

self.data=data

self.next=None

class LinkedList():

def init (self):

self.head=None

复制代码
def printList(self):
	ptr=self.head
	while ptr:
		print(ptr.data)
		ptr=ptr.next

link=LinkedList()

link.head=Node(5)

n2=Node(15)

n3=Node(25)

link.head.next=n2

n2.next=n3

link.printList()

相关推荐
紧跟先前的步伐2 分钟前
Go AI Agent 实战 12|HTTP 状态码、API 错误处理与日志
开发语言·人工智能·http·ai·golang
Demon--hx7 分钟前
C++ 文件流:理解 ifstream/ofstream 与 RAII 机制
开发语言·c++
benchmark_cc8 分钟前
个人量化系统搭建:如何利用 QuantDash 实现 A 股日 K 线前复权数据的高效获取与质量校验?
python·数据分析·pandas·量化交易·股票数据·quantdash
纪念 2299 分钟前
C++ stack和queue
开发语言·c++
hhb_61816 分钟前
Python异步队列实战:高效处理耗时任务
开发语言·python
2601_9628857219 分钟前
一个接口取 A 股+美股+港股:多市场数据方案对比
python
weixin_4166600720 分钟前
Mermaid流程图导出到Word:SVG、PNG与清晰度如何选择?
开发语言·c#
CodeYp201923 分钟前
第6讲:模板初阶
开发语言·c++·模板
SEO_juper26 分钟前
Node.js 全站死链检测工具:从 sitemap 出发一次找全 404
开发语言·人工智能·python·node.js·seo·外贸独立站
ljt272496066130 分钟前
Python笔记(九)--asyncio
笔记·python