c++ - Linked list to a file -


this question has answer here:

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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -