The question is related to the link list in data structures in c , how can we add data in the middle using only one pointer!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The question is related to the link list in data structures in c , how can we add data in the middle using only one pointer!!

We need to create a link list in c and than we need to add data between 2 addresses but the catch here is we need to use only one pointer (space complexity - saving space) I already know how we can do it using 2 pointers but need to know about using only one pointer Please provide a proper example and explanation of that code Your help is appreciated, thank you 🙇‍♂️

19th Jan 2023, 7:05 PM
Anand
Anand - avatar
5 Answers
0
Can you explain how you do it using 2 pointers? and BTW, what pointer type are we talking about here? Would help those who wanted to help if you could share your tryout code bit link (in post Description)
20th Jan 2023, 6:05 PM
Ipang
0
Technically you’ll always be using more than one pointer (or ref) as each node has a pointer to the next. Iterate list to get size. Create new obect (node). Change pointers next (for previous node at specific insertion point). I can post an example if you like.
20th Jan 2023, 10:50 PM
DavX
DavX - avatar
0
DavX there is a method which allows with one pointer i need that , i have examples of two pointers so i don't think I'll need that 😅
21st Jan 2023, 1:23 AM
Anand
Anand - avatar
0
Anand, Did you mean to "insert" a new node in between two nodes given their addresses?
21st Jan 2023, 4:52 AM
Ipang
0
Ipang it doesn't work like that
21st Jan 2023, 6:22 AM
Anand
Anand - avatar