当我尝试编译我得到预期*但参数是类型**,并且警告传递参数不兼容的指针类型

时间:2017-06-05 16:24:30

标签: c pointers graph dfs

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) i \,同时进入无限远时。

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);

}
}

这是清单。顺便说一下,程序正在运行,因为它应该只是那些警告困扰我向老师展示这个。如果你能告诉我如何解决这些问题我会很高兴。

1 个答案:

答案 0 :(得分:2)

很高兴看到所使用的函数的函数原型,但看起来你需要一个指向列表指针的指针,以便当removefront删除第一个节点并将指针重新分配给新头时,它不会丢失返回。

这是关于链接列表的精彩教程:http://www.learn-c.org/en/Linked_lists