Delete All Node From Link List Greater Than A Given Value
Linked-List |
Program:
void DeleteNode(node** head, int x)
{
node *ptr = *head;
node *prev,*temp,*temp1;
if((*head== NULL))
{
printf("\n\nlist is empty");
}
else if(ptr->data >x)
{
temp = ptr;
ptr=ptr->next;
free(temp);
}
else
{
temp = ptr;
prev = ptr;
printf("\n data : %d",temp->data);
while(temp!=NULL)
{
if (temp->data >x)
{
temp1 = temp;
temp=temp->next;
prev->next = temp;
free(temp1);
temp =prev;
}
else
{
prev=temp;
temp=temp->next;
}
}
}
}
0 comments:
Post a Comment