0
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 removefront (listT *plist, int *x)
{
if (isempty(plist) == 0)
{
nodeT *temp;
*x = plist -> front -> data;
temp = plist -> front;
plist -> front = temp -> next;
free(temp);
}
}
void DFS(int wierz){
int v;
nodeT *p;
addfront(&Stos, wierz);//adding element on stack
tabzaznaczen[wierz]==1;//array of visited elements
while(Stos){
removefront(&Stos, &v);
printf("%d", v);
for(p = tabwierz[v].front; p; p = p->next){//tabwierz is array of pointers to adjecent lists
if(tabzaznaczen[p->data]==0){
addfront(&Stos, p->data);
tabzaznaczen[p->data] = 1;
}
}
}}
私はスタック上でlisinitを使用し、それをグローバルに宣言しました。私はスタックと隣接リストを使ってグラフのためにDFSを書いています。それはうまく動作しません。
無駄な整数を追加するように動作しません。これは学校のための私のプロジェクトです。それは私のために重要です、私はそれが小さな間違いのようだと思うが、私はそれを見ることができません。
「そうすべきではない」とはどういう意味ですか?正確な問題は何ですか?何を修正しようとしましたか? – Martin
たとえば、0と1のグラフがリンクされていて、0からDFSを開始し、01の代わりに010を出力します。さらに複雑なグラフの開始要素を開始と中央に配置すると03041 –