I am facing run error

This is the ie for my code. Also, i woulde like to ask that i am facing runtime error for every code i write of linked list. could there be any specific reason for this happening in my code?

hey @Shwetatrisal, these things needs to change

  1. cin>>data should be inside while not outside, if you are doing show, then decrease value of n by 1 because you have read one value already.
  2. while(N-k+1), this condition will never becomes false. So you will remain in loop.
  3. it is mentioned in the question that k can be greater than N. If k>n, then make k=k%n. Example- n=2, k=3, 1->2 we need append last 3 element. If your append last 2 elements to front, LL attains original state which is 1->2. now for appending last one element it will become 2->1. Now if you observe carefully, for k=3, 2->1 is same result as for k=1(2->1) k=k%n=3%2=1 thatswhy you should do k=k%n when k>n.
  4. k can be 0 also in that case, appending last 0 elements to front means no change to LL.

I have made all these changes and indicated them as comment https://ide.codingblocks.com/s/108930

Now coming to your another doubt. Runtime error mostly occurs due these reason:

  1. you are accessing a node which is not exist.
  2. a variable taking very high value but the datatype you used is not sufficient to hold this value.
  3. infinte loop.

Thankyou sir for your valuable feedback.

hey @Shwetatrisal , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved