Skip to main content

一些广泛使用的数据结构

项目描述

py数据结构

抽象数据结构的Python实现

安装

pip install py-data-structures

涵盖的数据结构:

用法

from data_structures import Stack

stack = Stack()
stack.push(item)  # push an item in stack
stack.pop()  # returns and removes the top item from the stack
stack.length  # contains the length of the stack
stack.top  # contains the top item of the stack

stack.iterate()  # override to iterate or perform action on the stack elements

例外

from data_structures import exceptions

# raised on pop() or top when stack is empty
exceptions.EmptyStackException   

队列

用法

from data_structures import Queue

queue = Queue()
queue.enqueue(item)  # add an item at the end of queue
queue.dequeue()  # returns and removes the first item from the queue
queue.length  # contains the length of the queue
queue.first_item  # contains the first item in the queue
queue.last_item  # contains the last item in the queue

queue.iterate()  # override to iterate or perform action on the queue elements

例外

from data_structures import exceptions

# raised on dequeue(), first_item or last_item when queue is empty
exceptions.EmptyQueueException   

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

py-data-structures-0.2.1.tar.gz (3.2 kB 查看哈希)

已上传 source