栈的实现:
class Stack(object): def __init__(self): self.__list=[] def push(self,item): self.__list.append(item) def pop(self): return self.__list.pop() def peek(self): if self.__list: return self.__list[-1] def is_empty(self): return self.__list==[] def size(self): return len(self.__list) s=Stack() s.push(1) s.push(2) s.push(3) print(s.pop())
队列的实现:
class Queue(object): def __init__(self): self.__list=[] def enqueue(self,item): self.__list.append(item) def dequeue(self): if self.__list: return self.__list.pop() else: return None def is_empty(self): return self.__list==[] def size(self): return len(self.__list)
标签:__,.__,return,04,Python,self,list,数据结构,def From: https://www.cnblogs.com/yyyjw/p/18024591