【Algorithms】python 链表实现下压栈

用python实现了简单的下压栈,迭代功能一直无法实现0.0

class Node(object):
    def __init__(self,value=0):
        self.value = 0
        self.next = None
class Stack(object):
    def __init__(self):
        self.top = Node()
        self.current = self.top
        self.num = 0
        self.n = Node()
        self.item = 0
    def __iter__(self):
        return self
    def isEmpty(self):
        return self.num == 0
    

        
        
    def size(self):
        return self.num
    def push(self,value):
        self.n.next = self.top.next
        self.n.value = self.top.value
        self.top.value = value
        self.top.next = self.n
        self.num += 1
    def pop(self):
        self.item = self.top.value
        self.num -= 1
        self.top = self.top.next
        return self.item

 

你可能感兴趣的:(【Algorithms】python 链表实现下压栈)