#include
using namespace std;
class Node{
public:
int data;
Node *next;
Node(int d)
{
data = d;
next = NULL;
}
};
void insertAtTail(Node *&head,int data)
{
if(head == NULL)
{
head = new Node(data);
return;
}
Node *tail = head;
while(tail->next != NULL)
{
tail = tail->next;
}
tail->next = new Node(data);
return;
}
void print(Node *head, int q)
{
Node *slow = head;
Node *fast = head;
int count = q;
while(count>0)
{
fast = fast->next;
count–;
}
while(fast->next!= NULL)
{
fast = fast->next;
slow = slow->next;
}
Node *newHead = slow->next;
slow->next = NULL;
fast->next = head;
Node *temp1 = newHead;
while(temp1!=NULL)
{
cout<data<<" ";
temp1 = temp1->next;
}
return;
}
int main() {
int n;
cin>>n;
int d;
cin>>d;
Node *head = NULL;
for(int i=0;i<n;i++)
{
insertAtTail(head,d);
cin>>d;
}
int q = d;
print(head,q);
return 0;
}
This code giving me Run Error.