Hello Everyone!
I need help to create a buildList function that will build a linked list by inserting one int at a time into the front of the linked list from a text file.
And then prints out the numbers to the screen.
Here is what I have so far, and some problem during buildList...
#include <iostream>
usingnamespace std;
#include <fstream>
struct nodeType
{
int info;
nodeType * link;
};
void buildList (nodeType *&head);
void showList (nodeType *head);
int main (void)
{
nodeType *head =NULL;
StackADT <int> stack;//aggrument list for class template.
buildList (head);
showList (head);
return 0;
}
void buildList (nodeType*& head)
{
head = NULL;
head->link = NULL;
nodeType *temp;
temp = new nodeType;
int num;
ifstream myfile ("stackNumbers.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
myfile >> num;//get num from text file
temp->info=num;// stores num into a linked list
temp->link=head;//puts node in the list PROBLEM HERE
head = temp;// points head to a new node
}
}
myfile.close();
else
cout << "Unable to open file";
}
void showList (nodeType * head)
{
if (head !=NULL)
{
cout << head->info << endl;
showList (head->link);
}
}