I want to create an adjacency list based on data I get from a text file. Could I make this simpler?
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
struct Vertex;
struct Edges;
struct Edges
{
// edges link the vertex
Vertex * linkTo;
// pointer to vertex node
Edges * next;
};
struct Vertex
{
int parent;
int child1;
int child2;
int child3;
int child4;
int child5;
int child6;
int child7;
int child8;
Vertex * next;
Edges * Links;
// pointer to edges list
void Add_data(Vertex * node);
};
class Graph
{
public:
Vertex vertices;
// call the vertex struct to the Graph
private:
void BFS();
};
//-------------------------------- Function Implementation--------------------------
void Add_data(Vertex * node)
{
ifstream file("Table.txt");
string line;
int parent;
int child1;
int child2;
int child3;
int child4;
int child5;
int child6;
int child7;
int child8;
while(getline(file,line))
{
istringstream data(line);
if(!(data>>parent>>child1>>child2>>child3>>child4>>child5>>child>>6>>child7>>child8))
{
cout << "Error " <<endl;
}
else
{
node->parent = parent;
node->child1 = child1;
node->child2 = child2;
node->child3 = child3;
node->child4 = child4;
node->child5 = child5;
node->child6 = child6;
node->child7 = child7;
node->child8 = child8;
node->next = NULL;
}
}
}