Problem creating a linked list?

So the actual text file that will be used with the program is a lot larger but for now I'm using a small 12 line .txt file. The program is supposed to be creating a sorted linked list, but it always adds an extra item just containing the last line in the key position and the author and title blank. The code is supposed to have a database of articles with their key,author, and title.
Here's a few pieces of the code.(it's not having a problem sorting, I don't think. I overloaded the comparison operators):
IN main.cpp: ifstream read;
Article object;
string k,a,t;//key,author,title


//read.open("cacmpubs.txt");
read.open("test.txt");
if(!read)
{
cout<< "File not reading"<<endl;
exit(0);
}
else
{

bool until=true;
while(until)
{
if(read.eof() )
break;

getline(read,k);
getline(read,a);
getline(read,t);
cout<<k;//its not displaying the extra k item
Article temp(k,a,t);

articles.PutItem(temp);

}

In the LinkedList.cpp(PutItem function):
NodePointer temp;
NodePointer curr;
NodePointer prev;
prev=NULL;
curr = first;

if(first == NULL)
{
cout<<1;
temp = new Node(item);

first = temp;
first->next=NULL;
mySize++;

return;
}
else{
while(curr != NULL)
{
if(item==(curr->data))
{
cout<<"This key already exists!"<<endl;
return;
}
else if(item < (curr->data))
{

temp = new Node(item);
if(prev == NULL)
{
first = temp;
temp->next = NULL;
mySize++;

return;
}
else
{
cout<<2;
prev->next = temp;
(prev->next)->next = curr;
mySize++;

return;
}
}
prev = curr;
curr = curr->next;
}

prev->next=temp;
(prev->next)->next = NULL;
mySize++;


}
}

Last edited on
Topic archived. No new replies allowed.