/* void bubblesort(Node* head) { Node*i; Node*j; for(i=head;i!=NULL;i=i->next) { for(j=i->next;j!=NULL;j=j->next) { if(i->data>j->data) { int temp=i->data; i->data=j->data; j->data=temp; } } } } Node* append(Node*head,int n,int k){ Node*cur=head; Node*q=head; Node*p; for(int i=0;inext; } Node*cur1=cur->next; p=cur1; cur->next=NULL; for(int j=0;jnext; } p->next=q; return cur1; } */ #include using namespace std; class Node{ public: int data; Node* next=NULL; Node(int x) { data=x; } }; Node* createLL(int n) { Node* head=NULL; Node* tail=NULL; int i=0; while(i>x; Node* cur = new Node(x); if(!head) { head=cur; tail=cur; } else { tail->next=cur; tail=tail->next; } i++; } return head; } void print(Node* head) { Node* temp = head; while(temp) { cout<data<<" "; temp=temp->next; } } Node* appendK(Node* head,int k,int n) { if(!head) { return NULL; } Node* p=head; Node* q=head; if(knext; i++; } Node* newHead=p->next; p->next=NULL; Node* r = newHead; int j=0; while(jnext; j++; } r->next=q; return newHead; } else { k = k % n; int a=0; while(anext; a++; } Node* newHead=p->next; p->next=NULL; Node* r = newHead; int b=0; while(bnext; b++; } r->next=q; return newHead; } } int main() { int N; cin>>N; Node* head=createLL(N); int K; cin>>K; Node* head1=appendK(head,K,N); print(head1); }