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

I used lisinit on stack and declared it global.

Its not working like it should, adding some useless integers. This is my project for school. So it is important for me, I think its like a small mistake but I cant see it.

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
  • 1
    What do you mean by "not working like it should"? What's the exact issue? What have you tried to fix it? – Martin Jun 05 '17 at 13:56
  • For example i have graph of 0 and 1 linked, and i m starting DFS from 0, it print 010 instead of 01, and if i m doing more complicated graph starting element is on the start and middle for example 03041 – Maciek Nowacki Jun 05 '17 at 14:09

1 Answers1

0

Ok, i fixed it. I used == instead of = in one place.