As I know linked lists are not for input/output from files. It deppends on implementation. If you write linked list in a file, instead of pointers you will put offsets from the file or handles(yours defined values for each link) John Fill
Well, the simplified method of doing this would be to write the values to file. In other words walk the list to save it and then as you read in the data re-create the list. Make a class the reads/writes linked lists and that should do it.
Hi,
Your question is not clear. I am able to interpret that you want to save whatever is there in the link list in a file and then to create a link list from that file.
If my above interpretation is correct then following may help:
1. Consider each node of link list as a record in the file.
2. Whenever you want to save the link list, open the file in a create mode, traverse the list and add the data of each node in the file as a single record. For your convenience you should define the record length or should put some delimiter at the end of record while writing in a file. This will help you to determine the end of record when you will read the file.
3. When you want to load the file then open the file and read it record by record and create the linked list.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.