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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.