what is error in it
Linked list k append
Hi @vikashkmr519,
While calling the appendLastN method in main function, it is of the type appendLastN(LinkedList.Node, int) but you are using the arguments (LinkedList, int) (as you are calling appendLastN(Node head,int n), here head is a LinkedList.Node not the LinkedList). This is one error, because the arguments passed are wrong. Also, in appendLastN, list is undefined. The method has no definition of list.
it =s giving run time error whats the error , please tell me sir
Hi @vikashkmr519,
I have corrected your code for potential errors. Kindly check. https://ide.codingblocks.com/s/148708
I have commented lines 209 and 242. Kindly check.
Also, if k>n i.e. number of elements to be appended exceeds n, use k = k%n. Because after n appending operations all the elements will be back to their original position.
So in this case:
7
1 2 2 1 8 5 6
11
After 7 times, the linked list will be back to its original position. And then we have to do the appending for 4 times again.
still one test case is not passing
Hi @vikashkmr519,
Its a very trivial error.
Try the input:
2
1 2
2
This input will give you error. Check why and try to correct the code yourself. Ping me for further doubts.
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.