[英]Priority Queue 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 < PRIODIFF; i++) {
h = &(p->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]
兩次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.