queue.h:如何创建列表/队列/类似组合的列表?

时间:2016-09-09 10:44:31

标签: c linked-list queue dynamic-memory-allocation abstract-data-type

BSD的queue.h的

Man page清楚地显示了如何创建单/双链表/尾队列,但我无法获得如何创建,例如,列表列表或队列队列?特别是,如何处理从属查询的声明和初始化?

我尝试了什么:

//element of slave queue
struct slaveentry {
    STAILQ_ENTRY(slaveentry) pts;   //pointers
    /*data here*/
    } *selt;                        //element of queue

//element of master queue
struct masterentry {
    STAILQ_ENTRY(masterentry) pts;  //pointers
    struct slavehead *slave;        //pointer to slave queue head
    /*data here*/
    } *melt;                        //element of queue

//initialization of sturctures
STAILQ_HEAD(masterhead, masterentry) big_queue = STAILQ_HEAD_INITIALIZER(big_queue);
STAILQ_INIT(&big_queue);

//what's next? I don't know, maybe some sort of the following
STAILQ_HEAD(slavehead, slaveentry) small_queue = STAILQ_HEAD_INITIALIZER(small_queue);
STAILQ_INIT(&small_queue);

1 个答案:

答案 0 :(得分:0)

如果您对解决方案感兴趣,可以在此处查看:https://gist.github.com/postboy/fb825b9fe813a0a18d04ef4cdf2ac7a0

在我明白如何处理这个问题之前,我不得不花了一些时间,所以几天前这个问题出现在这里。