This is a small part of my project at school. I have stored my data into a text file in this form:
bike
dock
car
Now, I would like to read the data from this file into a doubly linked list. This is the code I used.
#include <iostream>
#include <strings.h>
#include <fstream>
using namespace std;
class item
{
public:
string name;
item *next;
item *previous;
};
class list:private item
{
item * first;
public:
list();
void load();
void display();
};
list::list()
{
first = NULL;
}
void list::load()
{
item *current;
ifstream fin;
fin.open("List.txt");
current=new item;
while(!fin.eof())
{
fin>>current->name;
current->previous=NULL;
current->next=NULL;
}
fin.close();
first=current;
}
Now, the problem is I am unable to store each word of the file into a new node. This code stores the last word of the file to the first node of the list. I have no clue how to do this. I am not that good in linked lists. Can anyone help me resolve this problem?