【问题标题】:queue.h: how to create list of lists / queue of queues / similar combinations?queue.h:如何创建列表列表/队列队列/类似组合?
【发布时间】:2017-01-17 11:58:31
【问题描述】:

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);

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-10
      • 2021-02-21
      • 2011-03-19
      • 2023-03-08
      • 2020-09-22
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      相关资源
      最近更新 更多