另一个python

时间:2016-03-02 06:21:00

标签: python data-structures doubly-linked-list

我想要做的是在python中创建双向链表类型的结构,然后使该双向链表成为另一个双向链表中的成员,并通过后者访问第一个。 我已经为它编写了代码,但是我无法从eshow访问ishow函数。它总是给出“无”。 我在这里发布我的代码。如果有人有任何建议或可以指出我的错误,请回复。 提前致谢

   #User defined Data Structure for Instance
class I(object):
    def __init__(self, prev, next, primary, secondary, tert_pre, tert_tag,itimestamp, iutility):
        self.prev = prev
        self.next = next
        self.primary = primary #list
        self.secondary = secondary #list
        self.tert_pre = tert_pre #list
        self.tert_tag = tert_tag#list
        self.itimestamp = itimestamp
        self.iutility = iutility

class IL(object):

    head = None
    tail = None
    from datetime import datetime
    itimestamp = datetime.now()   #to get current time
    iutility = 1

    def icreate(self, primary, secondary, tert_pre, tert_tag):
        from datetime import datetime
        itimestamp = datetime.now()   #to get current time
        iutility = 1
        new_node = I(None, None, primary, secondary, tert_pre, tert_tag, itimestamp, iutility)
        self.head = self.tail = new_node

    def iappend(self, primary, secondary, tert_pre, tert_tag):
        from datetime import datetime
        itimestamp = datetime.now()   #to get current time
        iutility = 1
        new_node = Instance(None, None, primary, secondary, tert_pre, tert_tag, itimestamp, iutility)
        if self.head is None:
            self.head = self.tail = new_node
        else:
            new_node.prev = self.tail
            new_node.next = None
            self.tail.next = new_node
            self.tail = new_node

    def ishow(self):
        print "Show Instance list data:"
        current_node = self.head
        while current_node is not None:
            print current_node.primary
            print current_node.secondary
            print current_node.tert_pre
            print current_node.tert_tag
            print current_node.itimestamp
            print current_node.iutility
            current_node = current_node.next



#User defined Data Structure for Episode
class E(InstanceList):
    def __init__(self, prev, next, etimestamp, link, link_weight, eutility, inst):
        #self.EpisodeID=EpisodeID
        self.prev = prev
        self.next = next
        self.etimestamp = etimestamp
        self.link = link
        self.link_weight = link_weight
        self.eutility = eutility
        self.inst = IL()

class EL(object):

    head = None
    tail = None
    from datetime import datetime
    etimestamp = datetime.now()   #to get current time
    eutility = 1
    w=0
    def eappend(self, primary, secondary, tert_pre, tert_tag):
        from datetime import datetime
        etimestamp = datetime.now()   #to get current time
        eutility = 1
        w=0
        inst = IL()
        inst.icreate(primary, secondary, tert_pre, tert_tag)
        new_node = E(None, None, etimestamp, None, w, eutility, inst)
        if self.head is None:
            self.head = self.tail = new_node
        else:
            new_node.prev = self.tail
            new_node.next = None
            self.tail.next = new_node
            self.tail = new_node


    def eshow(self):
        print "Show Episode list data:"
        current_node = self.head
        while current_node is not None:
            print current_node.etimestamp
            print current_node.link_weight
            print current_node.eutility
            print current_node.inst.ishow()
            current_node = current_node.next

0 个答案:

没有答案