python有内置的linkedList数据结构吗? [英] Does python have built-in linkedList data structure?

查看:115
本文介绍了python有内置的linkedList数据结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道 Python(可能是 2.7)是否有内置的 linkedList 数据结构?我知道队列是用list实现的,没有栈(有LIFO队列).

Does anyone know if Python (maybe 2.7) has a built-in linkedList data structure? I know the queue is implemented using list, and there is no stack (there is LIFO queue).

推荐答案

是的,Python 的 collections 模块 提供了 C 实现的 deque 对象,它使用了 BLOCKs 内部.

Yes, Python's collections module provides C-implemented deque object, which uses linked list of BLOCKs internally.

typedef struct BLOCK {
    struct BLOCK *leftlink;
    PyObject *data[BLOCKLEN];
    struct BLOCK *rightlink;
} block;

typedef struct {
    PyObject_VAR_HEAD
    block *leftblock;
    block *rightblock;
    Py_ssize_t leftindex;       /* 0 <= leftindex < BLOCKLEN */
    Py_ssize_t rightindex;      /* 0 <= rightindex < BLOCKLEN */
    size_t state;               /* incremented whenever the indices move */
    Py_ssize_t maxlen;          /* maxlen is -1 for unbounded deques */
    PyObject *weakreflist;
} dequeobject;

static PyTypeObject deque_type;

这篇关于python有内置的linkedList数据结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆