CrazyEngineers
  • How to store linked lists structures in a file ?

    Updated: Oct 26, 2024
    Views: 1.6K
    Consider a Tree, whose every parent node can have N child nodes. It's easy to store in structures during the execution of program For that I've implemented Linked Lists.
    But i wanted to store them in a Binary File, so that I don't need to input data again. I'm facing this problem since yesterday. Please, Help me OUT !!
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Ashish Bardhan

    MemberJan 14, 2012

    If you want to take a look on my problem code
    I could give my mail it to you. Gimme your email-id
    I guess in that way you'll get the problem.
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorJan 14, 2012

    Why don't you simply upload / post your problem code here?
    Are you sure? This action cannot be undone.
    Cancel
  • eternalthinker

    MemberJan 15, 2012

    Which language are you using? Many languages have libraries which enable you to dump whole datastructures to a file and re-build the datastructure from such a dump. In my knowledge, Java and Python has it. Just search on this conceptt for your language.

    This is the straightforward way. If such techniques are not inbuilt, write a function yourself to dump the datastructure into a file. Create your own notation to represent the data structure contents. Be creative and optimal in this 😀
    Are you sure? This action cannot be undone.
    Cancel
  • K!r@nS!ngu

    MemberJan 15, 2012

    ashbeezone
    Consider a Tree, whose every parent node can have N child nodes. It's easy to store in structures during the execution of program For that I've implemented Linked Lists.
    But i wanted to store them in a Binary File, so that I don't need to input data again. I'm facing this problem since yesterday. Please, Help me OUT !!
    Not getting what you are exactly asking for ????
    Can you mail me the code @ #-Link-Snipped-#
    so that i can try to help you out if possible in JAVA.
    Are you sure? This action cannot be undone.
    Cancel
  • Ashish Bardhan

    MemberJan 30, 2012

    eternalthinker
    Which language are you using? Many languages have libraries which enable you to dump whole datastructures to a file and re-build the datastructure from such a dump. In my knowledge, Java and Python has it. Just search on this conceptt for your language.

    This is the straightforward way. If such techniques are not inbuilt, write a function yourself to dump the datastructure into a file. Create your own notation to represent the data structure contents. Be creative and optimal in this 😀
    Kinda Helpful suggestion.
    Have you tried in C/C++ ??
    I'm just a beginner in Core JAVA !!
    Are you sure? This action cannot be undone.
    Cancel
  • Ashish Bardhan

    MemberJan 30, 2012

    K!r@nS!ngu
    Not getting what you are exactly asking for ????
    Can you mail me the code @ #-Link-Snipped-#
    so that i can try to help you out if possible in JAVA.
    Well, I'm trying to do in C/C++. For example, consider a simple data structure for a Linked List Node.
    struct list
    {
    int info;
    struct list *link;
    };

    Now I need to store this linked list in a binary file.
    If clear, then Try it out now.

    The_Big_K
    Why don't you simply upload / post your problem code here?
    I think the HINT which I've mentioned above is way better useful.
    Are you sure? This action cannot be undone.
    Cancel
  • Ashish Bardhan

    MemberJan 30, 2012

    However, I've discovered a solution of it : creating a replica data structure of linked list.

    Though originally the linked list node has the following data structure,

    struct list
    {
    int info;
    struct list *link;
    };

    But now I'm making a replica of the linked list node which has the following data structure,

    struct r_list
    {
    int info;
    };

    As an object of Class or even a Variable of Structure can be stored in a File using C/C++, I'll try to store them in the linear traversal order. So here's the technique:-

    Traverse the original linked list 'list' linearly. Store its 'info' first of every node to the 'info' of its replica 'r_list' and we can write the 'r_list' into Binary .DAT file. In other words, I've stored the linked list in linear traversed order using a temporary structure 'r_list'.

    Now in case, in case of reading and using the .DAT file. We can first store it to the 'r_list' and then create a new node by copying the 'info' of 'r_list' to that of 'list' and linking with the rear node on every iteration until there's nothing to read.

    This is how we'll probably get our linked list 'list' properly using File Handling in C/C++. Hopefully, it works !!
    Are you sure? This action cannot be undone.
    Cancel
  • Ashish Bardhan

    MemberJan 30, 2012

    Seems like now you've got my Point now.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register