Please help me how to make correct my append function of my code for this question
Hello @kailash_01,
There are mainly two mistakes in the problem:
-
To handle the case when k>=N:
do K=K%N;
This will, normalize the value of K to (0-N-1).
Example:
7
1 2 2 1 8 5 6
8
Expected Output:
6 1 2 2 1 8 5
Your Output:
1 2 2 1 8 5 6
Observation:
The required output is the same as that of k=1.
Similarly,
for k=7 the output is the same as that of k=0.
for k=9 the output is the same as that of k=2. -
For the case when k=N,2*N,⦠so on.
just return from the function.
Reason:
The linked list should remain unchanged. -
In your code you have handled the links incorrectly.
Refer to the comments for better understanding.
Hope, this would help.
Give a like if you are satisfied.
what is difference between while(lā) and whle(āl)
Hello @kailash_01,
-
Correction:
//it should be n not len
while(--n){
temp=temp->next;
} -
In while(nā), first it will check the value of n and then decrement it. While in while(ān), it will first decrement the value of n and then check it.
-
Why am I using while(ān)?
Because I want the loop to iterate for n-1 i.e. n-k-1 times.
Using n-- will iterate it for n-k times.
Hope, this would help.
Give a like if you are satisfied.