优先级队列C.
我正在尝试使用队列数组创建priority queue
,数组的每个索引都是优先级。 我尝试了以下解决方案,
队列数据类型包含数组llist,
Queue *q_create(int size) { struct queue *p; struct q_head *h; int i; if ((p = (struct queue *)malloc(sizeof(struct queue))) != NULL) { p->size = size; for (i = 0; i llist[i]); h->head = NULL; h->tail = NULL; } } return p; }
我h = &(p->llist[i]);
条线感到困惑: h = &(p->llist[i]);
我在想llist[i] = h
。 这是用C写它的另一种方式吗? 我正在读它,因为h = the address of llist[i]
。 它是否正确?
谢谢
我正在读它,因为h = llist的地址[i]这是正确的吗?
是。
是的,你应该读一下,将p->llist[i]
的地址分配给h
。 这与llist[i] = h
。
此代码使用h
作为简写,以避免必须为两个后续行键入p->llist[i]
两次。