cpws

    1. class LinkNode: # 结点
    2. def __init__(self, condition: iter):
    3. self.condition = condition # name: list
    4. self.next = None
    5. class BaseNode: # 单链表结点
    6. def __init__(self, **kw):
    7. self.next = None
    8. for k, v in kw.items():
    9. self.__setattr__(k, v)
    10. class SingleLinkList: # 单链表
    11. def __init__(self, node):
    12. self.head = None
    13. self.tail = None
    14. self.node = node
    15. def append(self, *args, **kw):
    16. if self.head is None:
    17. self.head = self.tail = self.node(*args, **kw)
    18. else:
    19. self.tail.next = self.node(*args, **kw)
    20. self.tail = self.tail.next
    21. @classmethod
    22. def create_then_append(cls, *args, node=BaseNode):
    23. """args有序"""
    24. instance = cls(node=node)
    25. for arg in args:
    26. instance.append(arg)
    27. return instance
    28. class ConditionEnum(Enum):
    29. AREA = "s33"
    30. WSLX_LIST = "s6"
    31. AY_LIST = "s11"
    32. FY_LIST = "s4"
    33. AJLX_LIST = "s8"
    34. class ConditionDynamicSingleLink(SingleLinkList):
    35. """根据ConditionEnum字段结合初始数据动态创建单向链表"""
    36. def __init__(self, init: dict, *args, **kw):
    37. super().__init__(*args, **kw)
    38. for field in [i.value for i in ConditionEnum]:
    39. if init.get(field):
    40. self.append(init.get(field))