Hello I have this problem where my text file is not read in properly to the linked list. It spits out only zeroes. Here is the code I have written. Thanks.
include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct widget
{
double R;
double S;
int P;
widget* next;
};
widget* temp = new widget;
widget* head_ptr = temp;
void widger();
int main()
{
string line;
ifstream inFile("data.txt");
if(inFile.is_open()){
while (inFile.good())
{
getline (inFile, line);
inFile >> temp->R;
inFile >> temp->S;
inFile >> temp->P;
temp->next = new widget;
temp = temp->next;
cout<< setw(25)<< temp->R << endl;
cout<< setw(25)<< temp->S << endl;
cout<<setw(25) << temp->P << endl;
}
temp->next == NULL;
}
inFile.close();
return 0;
}
void widger(widget* head_ptr)
{
widget* node = head_ptr;
widget* temp = NULL;
while(node->next != NULL)
{
if(node->R > node->next->R)
{
temp = node->next;
node->next = temp->next;
temp->next = node;
}
node = node->next;
}
}