python---数据结构---栈--进制转换

class SeqStack(object):
    def __init__(self):
        self.top=0
        self.StackSize=500
        self.stack=[None for x in range(0,500)]
    def StackEmpty(self):
        if self.top==0:
            return True
        else:
            return False
    def getTop(self):
        if self.StackEmpty() :
            print('empty')
            return None
        else:
            return self.stack[self.top-1]
    def push(self,e):
        if self.top>=self.StackSize:
            print('already ')
        else:
            print(self.top)
            self.stack[self.top]=e
            self.top+=1
    def pop(self):
        if self.StackEmpty():
            print('empty')
        else:
            self.top-=1
            a=self.stack[self.top]
            return a



if __name__=='__main__':
    mylist_A=SeqStack()
    def  DTB(num):
        num_b=[]
        while num:
            aa=num%2
            mylist_A.push(aa)
            num=num//2
        while mylist_A.StackEmpty():
            e=mylist_A.pop()
            num_b.append(e)

    DTB(3)

你可能感兴趣的:(python,数据结构,开发语言)