优先级队列C
我正在尝试使用队列数组创建一个优先级队列,该数组的每个索引都是一个优先级。我尝试了以下解决方案,
队列数据类型包含数组 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 < PRIODIFF; i++) {
h = &(p->llist[i]);
h->head = NULL;
h->tail = NULL;
}
}
return p;
}
我对以下行感到困惑: h = &(p->llist[i]);
我在想llist[i] = h
。 这是用C语言编写的另一种方式吗?我将其读为 h = llist[i] 的地址
。 这是正确的吗?
谢谢
I'm trying to create a priority queue
using an array of queues, each index of the array being a priority. I tried the following solution,
The queue data type contains an array 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 < PRIODIFF; i++) {
h = &(p->llist[i]);
h->head = NULL;
h->tail = NULL;
}
}
return p;
}
I'm confused by the line: h = &(p->llist[i]);
I was thinking that llist[i] = h
.
Is this another way of writing it in C? I'm reading it as h = the address of llist[i]
.
Is this correct?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。
Yes.
是的,您应该将其理解为将
p->llist[i]
的地址分配给h
。这与llist[i] = h
不同。此代码使用
h
作为简写,以避免在后续两行中键入两次p->llist[i]
。Yes, you should read that as assign the address of
p->llist[i]
toh
. This is not the same asllist[i] = h
.This code is using
h
as a short-hand to avoid having to typep->llist[i]
twice for the two subsequent lines.