首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这个队列为什么不能初始化?解决思路

2012-02-21 
这个队列为什么不能初始化?typedefstructQNode{/*单链队列--队列的链式存储结构*/intdatastructQNode*nex

这个队列为什么不能初始化?
typedef   struct   QNode
{/*   单链队列--队列的链式存储结构   */
int   data;
struct   QNode   *next;
}QNode,*QueuePtr;

typedef   struct   Queue
{
QueuePtr   front,rear;/*   队头、队尾指针   */
}Queue;

void   InitQueue   (struct   Queue   *Q)
{
(*Q).front=(*Q).rear=(QueuePtr)malloc(sizeof(struct   QNode));
assert((*Q).front!=NULL);
(*Q).front-> next=NULL;
}

int   isLoop(BayesNetwork   *nb)
{
int   m,i,j;
struct   Queue   *Q;
struct   ArcBox   *p;
Calindegree(nb);/*   通过nb.fealist[i].parent计算各点入度   */
InitQueue(Q);   /*   第166行   */
m=0;
for(i=0;   i <(*nb).feanum;   i++)
if((*nb).fealist[i].indegree==0)
Enqueue(Q,i);
while(NoEmpty(Q))
{
i=Dequeue(Q);
m++;
p=(*nb).fealist[i].child;
while(p!=NULL)
{
j=p-> head;
((*nb).fealist[j].indegree)--;
if((*nb).fealist[j].indegree==0)
Enqueue(Q,i);
p=p-> tlink;
}
}
if(m <(*nb).feanum)
return   0;
else
return   1;
}

编译后,出现警告:
D:\My   Documents\New\pass\AddArc.C(166)   :   warning   C4700:   local   variable   'Q '   used   without   having   been   initialized

到底是哪里出现了问题呢?在isLoop这个函数中,能否先定义一个Queue的指针变量,即*Q,不对它进行初始化,然后作为参数传递到InitQueue函数中,通过地址传递返回一个空队列呢?请大家指点,谢谢!

[解决办法]
按楼上的方法,
那么 InitQueue 函数也要修改了 ...

但是可能警告会被消除。

那个警告没有关系。
或者可以这样:
struct Queue *Q=NULL; //initialized

热点排行