编程知识 cdmana.com

Stack abstract data type and its implementation

Mind map of stack

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-AOIWcw7D-1583305647532)(https://leanote.com/api/file/getImage?fileId=5e5f4f3dab64416298006104)]

Code implementation

class Stack:
    '''
    @name:  data structure : Stack 
    @param {type} 
    @return: 
    '''
    def __init__(self):
        self.items=[]

    def push(self,item):
        '''
        @name:  Add an element to the stack ( To the top of the stack )
        @param {type} 
        @return: 
        '''
        self.items.append(item)
    def pop(self):
        '''
        @name:  Delete an element at the top of the stack 
        @param {type} 
        @return: 
        '''
        return self.items.pop()
    def peek(self):
        '''
        @name:  Find an element at the top of the stack 
        @param {type} 
        @return: 
        '''
        return self.items[-1]
    def isEmpty(self):
        '''
        @name:  Determine whether the stack exists 
        @param {type} 
        @return: True or False
        '''
        return self.items==[]
    def size(self):
        '''
        @name:  The length of the stack 
        @param {type} 
        @return: 
        '''
        return len(self.items)
    def see(self):
        '''
        @name:  View stack 
        @param {type} 
        @return: 
        '''
        return self.items

Follow me for more notes : Please indicate the source of the reprint , thank you ^_^

版权声明
本文为[jixn]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225102952151Z.html

Scroll to Top