Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++-linked list

Status
Not open for further replies.

jyotsna24

Programmer
Jun 24, 2001
15
0
0
IN
Hi,
How can we read and write from a file using linked list in cpp?pls show me an example pgm also.
Thanx in advance.
 
As I know linked lists are not for input/output from files. It deppends on implementation. If you write linked list in a file, instead of pointers you will put offsets from the file or handles(yours defined values for each link) John Fill
1c.bmp


ivfmd@mail.md
 
[offset to next|data][offset to next|data][offset to next|data]

is a very crude and simplified way of explaining it. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Did you ever get an answer to this problem?

Its just I'm having a similar problem
 
Well, the simplified method of doing this would be to write the values to file. In other words walk the list to save it and then as you read in the data re-create the list. Make a class the reads/writes linked lists and that should do it.

Good Luck.
jinappa
 
Hi,
Your question is not clear. I am able to interpret that you want to save whatever is there in the link list in a file and then to create a link list from that file.

If my above interpretation is correct then following may help:
1. Consider each node of link list as a record in the file.
2. Whenever you want to save the link list, open the file in a create mode, traverse the list and add the data of each node in the file as a single record. For your convenience you should define the record length or should put some delimiter at the end of record while writing in a file. This will help you to determine the end of record when you will read the file.

3. When you want to load the file then open the file and read it record by record and create the linked list.

VinKish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top