Deleting nodes having greater value on right side
In appendNode(), you have to provide a pointer to node to sizeof() and typecast its return value to struct node*:

void appendNode (struct node** headRef, int data)
{
    struct node* newNode = (struct node*)malloc(sizeof(struct node*));

    newNode-&gt;data = data;
    newNode-&gt;next = *headRef;
    *headRef = newNode;
}