本文介绍了优先队列C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用一个队列数组创建一个 priority队列
,该数组的每个索引都是一个优先级.我尝试了以下解决方案,
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,
队列数据类型包含一个数组llist,
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;
}
我对这行感到困惑: h =&(p-> llist [i]);
我当时在想 llist [i] = h
.这是用C编写的另一种方式吗?我将其读取为 h = llist [i]
的地址.这是正确的吗?
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?
谢谢
推荐答案
是的
这篇关于优先队列C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!