I am trying to write a program to serialize a linked list to a file without using any libraries. My problem is how to add or remove nodes to the serialized structure since I dont have next pointer ? Also how can I avoid fragmentation ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your linked list doesn’t have loops, then the fact that this is a “linked list” is a memory detail, not a serialization detail. Just write the node values out into the file and build the
nextpointers when you deserialize.However, if your linked list does have loops, then you’ll need something smarter. You’ll need to store
nextpointers as a file offsets to the node (or something similar) to encode the “link”.For each node in your linked list, store two words. The first is the data, the second is the offset of the
nextnode. Here is an illustration of the circularly linked list: