Skip to content Skip to main navigation Skip to footer

Python中关于栈的类的分析

Python中关于栈的类是如何来使用的呢?下面的内容将会通过具体的实例来演示Python中关于栈的类的使用方法及相关技巧:

本文实例讲述了python栈类。分享给大家供大家参考。具体如下:

class Path: #a list used like a stack
    def __init__(self):
        self.P = []
    def push(self,t):
        self.P.append(t)
    def pop(self):
        return self.P.pop()
    def top(self):
        return self.P[-1]
    def remove(self):
        self.P.pop(0)
    def isEmpty(self):
        return (len(self.P)==0)
    def printPath(self):
        print self.P
 


Python中关于栈的类就是这样,欢迎大家参考。。。。

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.