Hello, I have simply returned the original list without changing if k > N but I an getting only half of the cases passed. Please help me where I am wrong.
Here is my code:
#include
using namespace std ;
class node{
public:
int data ;
node * next ;
node(int d){
data = d ;
next = NULL ;
}
} ;
void insert_at_Tail(node* &head, int d){
if(head == NULL){
head = new node(d) ;
return ;
}
node* temp = head ;
while(temp -> next != NULL){
temp = temp-> next;
}
node * n = new node(d) ;
temp-> next = n ;
}
void append(node* &head,int n, int k){
if(k >= n ) return ;
node* slow = head ;
node* fast = head ;
for(int i = 0; i < k; i++){
fast = fast -> next ;
}
while(fast -> next != NULL){
slow = slow -> next ;
fast = fast -> next ;
}
fast -> next = head ;
head = slow -> next ;
slow -> next = NULL ;
}
int main() {
int n ;
cin >> n ;
node * head = NULL ;
int l = n ;
while(l--){
int t;
cin >> t ;
insert_at_Tail(head,t) ;
}
int k ;
cin >> k ;
append(head,n,k) ;
node* temp = head ;
while(temp != NULL){
cout << temp -> data <<" " ;
temp = temp -> next ;
}
return 0;

