In my c program I creating a singly linked list where we have to insert a node using the prev node, I'm getting this error in my main() function:
Dereferencing pointer to incomplete type ‘struct Node’
I am not sure why is it giving that error.
while((temp->next != NULL) && (temp->next->data < randomNumData)) -- error here
typedef struct _Node
{
int data;
struct Node *next;
} ListNode;
ListNode *newList();
ListNode *insertNode(ListNode *prev, int data);
int main()
{
ListNode *head = newList();
int randomNumData;
ListNode *temp = head;
int i;
for(i = 0; i < 11; i++)
{
randomNumData = random()%1001;
while((temp->next != NULL) && (temp->next->data < randomNumData))
{
temp = temp->next;
}
temp->data = randomNumData;
head = insertNode(temp, randomNumData);
}
printList(head);
}
// returning the head of a new list using dummy head node
ListNode *newList()
{
ListNode *head;
head = malloc(sizeof(ListNode));
if(head == NULL)
{
printf("ERROR");
exit(1);
}
head->next = NULL;
return head;
}
ListNode *insertNode(ListNode *prev, int data)
{
ListNode *temp = prev;
prev->next = temp->next;
temp->next->data = data;
return temp;
}
ListNodeandstruct Node?ListNode?struct Node *next;-->struct _Node *next;struct Node *next;but there is nostruct Nodedefined anywhere.