I have to print out every unique integer in a linked list, it turned out the it's not printing anything.I tried using continue and remove the else but by doing that I only get the first unique item in the linked list. My question is that does continue end the loop or just skip the current iteration? If it only skips the current one, say i have a linked list that looks like 1->5, why am I only getting 1 printed here? Thanks in advance.
struct node {
int data;
struct node* next;
}
void printList(struct node *head) // print out unique items of the list
{
struct node *ptr = head;
struct node *prev = NULL;
while(ptr != NULL)
{
if(prev->data == ptr->data)
{
prev = ptr;
ptr = ptr->next;
}else{
printf("%d", ptr->data);
prev = ptr;
ptr = ptr->next;
}
}
}
struct nodelook like?breakbreaks out of the loop,continue... continues the loop. That's very basic C knowledge covered in every C text book.prev->data.prev = ptr; ptr = ptr->next;which are needed whether or not there was a match found.