Linked List-K Append

void headprint(node* head,int k){
node* fast = head,*slow = head,t = head;
int c = 0;
while(c<k && fast!=NULL && fast->next!=NULL){
fast = fast->next->next;
slow = slow->next;
c++;
}
node
tem = slow->next;
slow->next = NULL;
fast->next = head;
print(tem);
}

can u see what is wrong in my code


Node* KAppend(Node *&head,int n,int k){
	Node * curr = head;
	Node * prev = head;
    k%=n; // jumps = 7-3 = 4
    while(k > 0){
    	curr = curr->next;
    	k--;
	} // move one pointer k step forward
    while(curr->next != NULL){
        curr = curr->next;
        prev = prev->next;
    } // prev points at n-k nodes

    // just join curr pointer to head of original linked list
    // 1 2 3 4 5-> 1 2  .... -> break the link now 
    curr->next = head;
    head = prev->next;
    // break the link here
    prev->next = NULL;
    
	prev->next = NULL;
	return head;
}

@Somith
image

the desired o/p is :
1 8 5 6 1 2 2

u need to move the last k elements to front.
and also k can be greater than size of linked list