As a part of the programming Assignment, I have to maintain a linked list in text file. I am pretty convenient with Linked List datastructure, but not so much with files in C++. Can some one give me an idea or overview of how to approach it. I should be able to add or delete the linked list, also able to add or delete the nodes in the linked list or else and should reuse the space that was deleted on one linked list. Each list has a number(integer), all nodes are of same size, contain integer.
My idea would be,
1) maintain a file with numbers(that contain linked List numbers)
0 - NULL
1 - head_offset for_linked_list_num 1
0 - NULL
1 - head_offset_for_linked_list_num 3
1 - head_offset_for_linked_list_num 3
1 - head_offset_for_linked_list_num 3
etc
where -1 is the termiator indication, 1 in a position indicates the ith location has an location associated with it
2) open another file and maintain the linked list like this
data next_offset
data next_offset
data NULL
By doing this, I can keep track of the linked list and efficiently add/delete/display an array.
For doing in C++ what are the functions I need to know and learn. I have very less time and I can code thinking it as an basic level of functions. Please advise. Thanks in advance
1 solution could be to have each list it’s own file. The number would be the file name on disk. Inside of the file the first line is always the head node. Each line would be two peices of data. The node data followed by the line in the file for the next node. This would allow you to reuse empty spaces that have been deleted. (a -1 for the next node line would be the end of the list. For example:
1.txt:
So this link list would be 18 -> 32 -> 5 -> 4