Remove all elements from a linked list of integers that have value val.
Example:
Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeElements(struct ListNode* head, int val) {
if(head==NULL)
return head;
struct ListNode *hhead;
hhead=(struct ListNode *)malloc(sizeof(struct ListNode));
hhead->next=head;
head=hhead;
while(head->next!=NULL)
{
if(head->next->val==val)
head->next=head->next->next;
else
head=head->next;
}
return hhead->next;
}