K append linked list

what is the mistake i am doing here
#include
using namespace std;

class node
{
public:
int data;
node *next;
node(int d)
{
data = d;
next = NULL;
}
};

void insertathead(node *&head, int d)
{
if (head == NULL)
{
head = new node(d);
return;
}

node *n = new node(d);
n->next = head;
head = n;

}

void print(node *&head)
{
while (head != NULL)
{
cout << head->data << " ";
head = head->next;
}
}

node *append(node *head, int k)
{
node *old = head;
node *fast = head;
node *slow = head;
while (fast->next != NULL and k > 0)
{
fast = fast->next;
k–;
}

while (fast->next != NULL and fast != NULL)
{
    fast = fast->next;
    slow = slow->next;
}

node *newhead = slow->next;
slow->next = NULL;
fast->next = old;
return newhead;

}

int main()
{
int n;
cin >> n;

node *head1 = NULL;
int k;
cin >> k;
int d;
for (int i = 0; i < n; i++)
{
    cin >> d;
    insertathead(head1, d);
}

if (k == 0)
{
    print(head1);
}
else
{
    node *head2 = append(head1, k);
    print(head2);
}

return 0;

}

hi @abhinavssr2003_eab0717682969e5c send the code on ide.codingblocks.com

hi @abhinavssr2003_eab0717682969e5c,
add at tail not on head and take input of k after making list not before

still four test cases are failing

hi @abhinavssr2003_eab0717682969e5c suppose k is 1000 and n is 5 then u dont need to rotate any no of time right as it if a factor of 5 it will be eqv to 0 rotations, so after taking k as input do
k %= n; this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.