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

And when i change declaration to listT Stos; its revealing error: used struct tpye value when scalar is required. And then when i change to while(&Stos) i\while goes to infinity.

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

}
}

This is the list. By the way program is working as it should just those warnings are bothering me to show this to my teacher. If u could tell me how to fix those i would be pleased.

  • What is the **exact** error message? – Oliver Charlesworth Jun 05 '17 at 16:26
  • 3
    Please take some time to [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask) and learn how to create a [Minimal, **Complete**, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Jun 05 '17 at 16:26
  • 2
    The function expecting a pointer `listT*` but being passed a pointer-pointer `listT**`, and then the infinite while loop are the big clues here. `&Stos` is a pointer-pointer. – Justin J. Jun 05 '17 at 16:31
  • Question is on hold and I can't post an answer, so I'll answer in comment. Change `listT *Stos;` to `listT Stos;` Otherwise you are passing the address of an uninitialized pointer to function expecting pointer to listT. – Justin J. Jun 05 '17 at 18:39
  • Alternatively, `listT* Stos = malloc(sizeof(listT));` and `addfront(Stos, 1);` – Justin J. Jun 05 '17 at 18:49

1 Answers1

2

It would be nice to see the function prototypes of the functions used, but it looks like you need a pointer to your list pointer so that when removefront deletes the first node and reassigns the pointer to the new head it is not lost when returning.

Here is a wonderful tutorial on linked lists: http://www.learn-c.org/en/Linked_lists

Grifplex
  • 192
  • 1
  • 12