链表对象的建立和循环输入输出
# 建立一个链表的类
class student:
def __init__(self):
self.name = ''
self.next = None
# 首先建立一个头指针
head = student()
head.name = 'head'
# 新建一个操作指针
ptr = head
# 新建若干个项,放在链表中
for i in range(5):
ll = student()
ll.name = str(input("loop {} of {}, please input names:".format(i+1,5)))
ptr.next = ll
ptr = ptr.next
依次输入如下:
loop 1 of 5, please in