【发布时间】:2017-06-06 01:42:57
【问题描述】:
listT *Stos;
void DFS(int wierz) {
int v;
nodeT *p;
addfront(&Stos, wierz);
tabzaznaczen[wierz] = 1;
while (Stos) {
removefront(&Stos, &v);
printf("%d\n", v);
for (p = tabwierz[v].front; p; p = p->next) {
if (tabzaznaczen[p->data] == 0) {
addfront(&Stos, p->data);
tabzaznaczen[p->data] = 1;
}
}
}
当我将声明更改为listT Stos; 时,它显示的错误是:在需要标量时使用了 struct tpye 值。然后当我更改为while(&Stos) 时,我\while 去无穷大。
typedef struct nodeTAG{
int data;
struct nodeTAG *next;
}nodeT;
typedef struct listTAG{
nodeT *front;
nodeT *end;
}listT;
void listinit (listT *plist)
{
plist -> front = NULL;
plist -> end = NULL;
}
int isempty (listT *plist)
{
if (plist -> front == NULL)
return 1;
else return 0;
}
void addfront (listT *plist, int x)
{
nodeT *temp;
temp = (nodeT*)malloc(sizeof(nodeT));
temp -> data =x;
if (plist -> front == NULL)
{
temp -> next = NULL;
plist -> front = temp;
plist -> end = temp;
}
else
{
temp -> next = plist -> front;
plist -> front = temp;
}
}
void addend (listT *plist, int x)
{
nodeT *temp;
temp = (nodeT*)malloc(sizeof(nodeT));
temp -> data = x;
if (plist -> front == NULL)
{
temp -> next = NULL;
plist -> front = temp;
plist -> end =temp;
}
else
{
temp -> next = NULL;
plist -> end -> next = temp;
plist -> end = temp;
}
}
void removefront (listT *plist, int *x)
{
if (isempty(plist) == 0)
{
nodeT *temp;
*x=plist->front->data;
temp = plist -> front;
plist -> front = temp -> next;
free(temp);
}
}
这是列表。顺便说一句,程序正在正常工作,只是那些警告正在困扰我向我的老师展示。如果你能告诉我如何解决这些问题,我会很高兴。
【问题讨论】:
-
确切错误信息是什么?
-
该函数需要一个指针
listT*,但被传递一个指针指针listT**,然后无限循环是这里的主要线索。&Stos是一个指针指针。 -
问题被搁置,我无法发布答案,所以我会在评论中回答。将
listT *Stos;更改为listT Stos;否则,您会将未初始化指针的地址传递给期望指向 listT 的指针的函数。 -
或者,
listT* Stos = malloc(sizeof(listT));和addfront(Stos, 1);
标签: c pointers graph microsoft-distributed-file-system