c++ - Linked list to a file -
this question has answer here:
- c - serialization techniques 4 answers
i have single linked list follows.
/*nodetype definitions*/ #define int 1 #define float 2 #define double 3 typedef struct { int nodetype; void* node_data;//this field dynamically allocated node* next; }node;
the data type of node changed according type of node (nodetype
). how can store linked list in file. how can create structure new file type ?
it depends on how want use data in file.
in typical case, treat linked list sequence. when you're storing data in file, ignore links, , store sequence of data. when need read in, read in record, put in node, read record, put in next node, , on until reach end of file.
the obvious alternative if want able treat data on disk linked list -- i.e., able insert records in middle of sequence minimum of modifications. in such case, you'll typically replace pointers in memory version file offset of next record. when/if want insert in middle of sequence, pointers, manipulating file offsets.
Comments
Post a Comment