This is a part of the header file
using namespace std;
namespace graph {
typedef string Name;
typedef bool Male;
typedef string Relation;
typedef int Age;
struct Node;
struct Vertex;
typedef Node* Grafo;
typedef Vertex* AdjacentList;
const Grafo emptyGraph = NULL;
const AdjacentList emptyAdjacentList = NULL;
}
Here is the struct I used to implement the data structure linked adjacency list;
struct graph::Node {
Name nome;
Male maschio;
Age anni;
Node* next;
Vertex* adjList;
};
struct graph::Vertex {
Node* vertPtr;
Relation rel;
Vertex* next;
};
here is the function that gives me the error
it should add the relation to the persons one example of call could be:
addRelation(Mark,Lucas,Dad,Son,g)
bool graph::addRelation(Name n, Name m, Relation rel1, Relation rel2, Grafo & g) {
if (n == m) //I make sure the two persons I wanna bond aren't the same one
return false;
Node * first = g; //I initialize a ptr and I iter util it point to the desired person
while (first != emptyGraph && first -> nome != n)
first = first -> next;
if (first == emptyGraph)
return false;
Node * second = g; //same with second person
while (second != emptyGraph && second -> nome != m)
second = second -> next;
if (second == emptyGraph) //if one of them is missing we exit
return false;
if (first -> adjList != emptyAdjacentList) {
Vertex * auxFirst = first -> adjList;
while (auxFirst -> next != emptyAdjacentList && auxFirst -> vertPtr -> nome != m)
auxFirst = auxFirst -> next;
if (auxFirst -> vertPtr -> nome == m)
return false;
Vertex * secondHalfEdgeToAdd = new Vertex;
auxFirst -> next = secondHalfEdgeToAdd;
auxFirst -> rel = rel1;
auxFirst -> vertPtr = first;
auxFirst -> next = emptyAdjacentList;
}
}
I dunno why I still need to add details otherwise I can't post this so I'm just writing this phrase hoping this works;