K reverse in lists using STLs

  1. i have passed test cases but i was not able to generate
    a list,help me in generating the list with STL only

  2. do we use STL’s for list or should we make our own class of nodes

You are facing issue in initialisation of list STL or what? Please mention

Preferable is to use STL list cause by using it, we avoid writing a long code. STL list provides convenience , so would recommend it to use while doing competitive Programming .

i didn’t make a list instead i printed output but i want to generate a list and then print it as a whole

Check this, these are list operations. If you have anymore doubts left please mention here by elaborating it here.

can you solve this question for me

i want to make a list connecting all the nodes the way asked in the question

okay so you want to solve k reverse linked list question using STL?

  ----------yes    sir------

so to do it using STL, what you need to do is take ceil(n/k) linked list insert k elements in each linked list, reverse each of them separately, and then print all in same sequence .
For eg:

if Original LL is : 9 -> 4 -> 1-> 7 -> 8 -> 3-> 2 -> 6 -> 5
and value of n =9 & k = 3
so you will be needing ceil(9/3) that is 3 linked list l1, l2 & l3
insert k elements in these 3 linked list 
l1 = 9 -> 4 -> 1
l2 = 7 -> 8 -> 3
l3 = 2 -> 6 -> 5
Now reverse these 3 linked list seperately
l1= 1 -> 4 -> 9
l2= 3 -> 8 -> 7
l3= 5 -> 6 -> 2
now print them in l1,l2 & l3 sequence that is
1 -> 4 -> 9 -> 3 -> 8 -> 7 ->5 -> 6 -> 2


1 Like

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.