1 #!/usr/bin/env python
 2 
 3 class StudentNode(object):
 4         def __init__(self, name, age, next_=None):
 5                 self.student = [name, age]
 6                 self.next = next_
 7 
 8 class StudentList(object):
 9         def __init__(self):
10                 self.head = None
11                 self.num = 0
12 
13         def prepend(self, name, age):
14                 self.head = StudentNode(name, age, self.head)
15                 self.num += 1
16 
17         def bianli(self):
18                 p = self.head
19                 li = []
20                 while p:
21                         li.append(p.student)
22                         p = p.next
23                 return li
24 
25 if __name__ == '__main__':
26         s = StudentList()
27         s.prepend("xuqiang",18)
28         s.prepend("lisa",20)
29         print(s.bianli())

 

结果:

[['lisa', 20], ['xuqiang', 18]]

相关文章:

  • 2022-12-23
  • 2021-04-01
  • 2021-06-17
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案