Saving a Linked List to a Disk File - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Saving a Linked List to a Disk File

laualaua Posts: 1Member
Can someone explain to me how to save a linked list onto a disk file. When I try the usual 'write' statements, I get error messages. I have searched my text and the web, but can come up with nothing.

I have created a program that allows users to enter information which is then put into a linked list. The problem is that I can't get it to write the info to the disk, so whenever I start the program again, the file is read as gibberish.

Please help.



  • stevesteve Posts: 43Member
    In general, when writing a linked list out to a file it is totally unnecessary
    to write out the linking information, simply write out the records in the
    order that the list determines. When reading back in simply add the
    records to the list one at a time until you get to the end of the file.

    Supposing your list was on the heap then the data types might be:

    yourdatatype = record ......{as required}

    heaptype = record
    data : yourdatatype ;
    prev,next : pointer ;
    end ;

    The file is then simply one of yourdatatype and should work with the normal
    read and write statements.

Sign In or Register to comment.