c - 队列.h : how to create list of lists/queue of queues/similar combinations?

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

Man page BSD的queue.h清楚地显示了如何创建单链表/双链表/尾队列,但我不知道如何创建例如列表列表或队列队列?特别是,如何处理从属查询的声明和初始化?

我尝试了什么:

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

最佳答案

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

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

关于c - 队列.h : how to create list of lists/queue of queues/similar combinations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39409785/

相关文章:

c - 如何删除两个索引之间的链表节点?

c - 如何遍历多级链表?

javascript - Html5 Websocket 和顺序处理队列

java - 任何可用于将消息从 COBOL 发送到 Java 的开源消息队列?

c - 在 C 中发送/接收 SOAP 请求/响应

c - 进程间如何发送信号?

c - C 中两个程序之间的管道

c - 错误初始值设定项元素不是常量

c++ - 为什么迭代链表中的节点不是 C++ 中的赋值?

laravel - 使用 Laravel Mail::later 时缺少对象