wrong output
Linked list k append
i have done some changes you can check now i give correct output
- modification in input() your input function taking one less input
- if(k==n) no change return
- if(k>n) k=k%n;
- line 47-49
temp->next = head;
head = temp2->next;
temp2->next = NULL;
Modified Code
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
in the question it is asked that we have to append last k nodes…
- if k==n isn’t this means that we nee need to append the last node in the front
- and if k>n why do we need to do any operation
and still the code is showing wrong output after the changes
just print output in next line for each testcase
code will pass all testcases
if k==n means you have append n element at front means nothing happen
suppose list is
1 2 3 4 5
if k=3
3 4 5 1 2
if k=5
1 2 3 4 5
if k=7 means move only 2 elements
4 5 1 2 3
so for k>n we replace k=k%n;
it is similar to circular traversal
still showing wrong output
i have done the same thing but it is still showing wrong output please look my code once
these else if condition are wrong
due to this only one will be executed
which is wrong
Modified Code
see the code which i have provide you