check the code here :
π‘ Linked List-K Append idk why its showing error
@sonishivam417
Please share your entire code and not just a snippet. Its possible there may be a issue with the rest of the code.
please check now i have mentioned the class and create function along with print function https://ide.codingblocks.com/s/104095
@sonishivam417
I still need the main( ). I think the main issue is in the main function only. Hereβs my guess , have you considered the case when k is greater than n ? What are you doing for it ?
Try this testcase :
7
1 2 3 4 5 6 7
10
Expected Output :
5 6 7 1 2 3 4
Please share your entire code including the main( ) next time .
@sonishivam417
As I said in my previous reply , you are not considering the case when K is larger than N. In such a case you should consider taking the modulo of K i.e. k = k % n and then do the remaining procedure as usual. This will ensure that your k becomes less than n.
Try this out and let me know if you face any problem
Do not forget to consider the corner case when k is a multiple of n i.e. when k % n comes out to be 0.
In such a case , do not call the append function at all but rather simply print the list as it is.
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.