why the segmentation fault is coming
Linked list K_append
because you are not passing head by reference in insert_at_tail() function
so linked list is not formed hence give segmentation fault when you try to use head->next;
void insert_at_tail(node *&head, int data) {