|
楼主 |
发表于 2019-9-12 23:46:46
|
显示全部楼层
- # -*- coding: utf-8 -*-
- """
- Created on Thu Sep 12 23:13:38 2019
- """
- class Node(object):
- def __init__(self):
- self.val = None
- self.next = None
- class Node_handle():
- def __init__(self):
- self.cur_node = None
- def add(self,data):
- node = Node()
- node.val = data
- node.next = self.cur_node
- self.cur_node = node
- return node
- l1 = Node()
- ListNode_1 = Node_handle()
- l1 = ListNode_1.add(2)
- l1 = ListNode_1.add(4)
- l1 = ListNode_1.add(3)
- while l1:
- print ('\nnode: ', l1, ' value: ', l1.val, ' next: ', l1.next)
- l1 = l1.next
- l2 = Node()
- ListNode_2 = Node_handle()
- l2 = ListNode_2.add(5)
- l2 = ListNode_2.add(6)
- l2 = ListNode_2.add(4)
- while l2:
- print ('\nnode: ', l2, ' value: ', l2.val, ' next: ', l2.next)
- l2 = l2.next
复制代码 |
|