I have problems printing a singly linked list,it must look for example so: [1:2][3:4][7:2][9:1], but the result/the output is without the last element, i.e. so: [1:2][3:4][7:2]. This is my data-structure:
struct numbers {
int info1;
int info2;
numbers *next;
};
struct numbers* next= NULL; //At first 0,because the list is empty
struct numbers* head=NULL; //at the beginning
And the function,that I call later:
void printing(numbers *head) {
numbers *temp=head;
if(head!=NULL) {
do {
printf("[%d:%d]",temp->info1, temp->info2);
temp=temp->next;
} while(temp->next!=head && temp->next!=0);
}
return;
}
Is there a mistake in this function?
I do not understand the condition
The last node is not outputed because instead of
you have to check
because you already moved the pointer inside the loop
So the function is wrong. It should look like