2017-06-05 66 views
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圖表使用堆棧和目錄列表,它不像它應該

它不工作就像它應該添加一些無用的整數。這是我的學校項目。所以這對我很重要,我認爲它就像一個小小的錯誤,但我無法看到它。

+1

你是什麼意思「不工作應該」?什麼是確切的問題?你有什麼試圖解決它? – Martin

+0

例如我有0和1鏈接圖,我從0開始DFS,它打印010而不是01,如果我做更復雜的圖起始元素是在開始和中間例如03041 –

回答

0

好的,我修好了。我在一個地方使用==而不是=。

相關問題