Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
ok in this code the program is running but there is a problem the first insertion of data to the linked list
i get duplicated output on the print this is the code im running codeblocks 13.12 :
p.s
i also like to learn the logic why this is happen. tnx in advance
Hi,
It would take a long time to point out and explain all the bugs in this piece of code, so here's a very short list:
1. The Insert() function is not inserting the elements - it is Append()-ing them -> that's quite a big difference.
2. The first element is indeed doubled, because there's missing return statement in the header initialization:
if(head == NULL) {
struct node* temp = malloc(sizeof(struct node));
temp -> data = c;
temp -> next = NULL;
head = temp;
return; /* !HERE! */
}
3. In the scheme which is used in Your code, the Header should be simply a pointer to the first element and the above fragment of code is simply redundant.