How to store linked lists structures in a file ?

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 !!

Replies

  • Ashish Bardhan
    Ashish Bardhan
    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.
  • Kaustubh Katdare
    Kaustubh Katdare
    Why don't you simply upload / post your problem code here?
  • eternalthinker
    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 😀
  • K!r@nS!ngu
    K!r@nS!ngu
    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.
  • Ashish Bardhan
    Ashish Bardhan
    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 !!
  • Ashish Bardhan
    Ashish Bardhan
    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.
  • Ashish Bardhan
    Ashish Bardhan
    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 !!
  • Ashish Bardhan
    Ashish Bardhan
    Seems like now you've got my Point now.

You are reading an archived discussion.

Related Posts

Is it possibile to transmit Electrical Energy without wire ? If yes then in which stage the research is?
Genesis 2012 is an All India Inter Collegiate Technical Symposium organized by Pondicherry Engineering College. As technology advances, it reverses the characteristics of every situation again and again. With technology...
hi guys, it will helpful for current student if our seniors post some problems which are being faced in industry, as it gives exposure to real time problems of industries.........
Consider a circuit with Xs reactance and Rs resitance connected in series. We apply supply voltage Vs at the input terminal and Vr is the output voltage. The current is...
Regular CEans have noticed that we're introducing new sections and also considering splitting existing sections for better management of content. We need your feedback on the following - 1. Have...