Take_input function for n number of inputs in Linkedist

input
n=5
4 5 3 5 8
output
8 5 3 5 4

n = 4
4 3 2 1
output
1 2 3 4

hello @TheSourabh

what is ur doubt?

Hey @TheSourabh you have reopened your doubt, you can tell what issue you are facing.

Loop is terminating when user enter -1
I want Loop is terminate when all 5 elements inserted
n = no of elements

Please don’t reopen multiple times until anyone replies. If someone does reply to doubt, reply instead of reopen :slight_smile:
Moreover, do you want me to send you the code for taking n inputs or tell you the approach?

You can make a function like this where head is the head of the linked list and n is the number of elements you want to insert in linked list


If this solves your doubt, mark it as resolved .

@mr.encoder please send code

Here’s the code for the same

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.