This skips the first line for me when I try it:
1 2 3 4 5 6 7
|
while (getline (inputFile, line))
{
inputFile>>v1>>v2>>w;
edge = Edge(v1,v2,w);
edgeHeap.insert(edge);
list.buildGraph(edge);
}
| |
you could do
1 2 3 4 5 6
|
while (inputFile>>v1>>v2>>w)
{
edge = Edge(v1,v2,w);
edgeHeap.insert(edge);
list.buildGraph(edge);
}
| |
Moving on,
|
list[inEdge.first()-1].next = neighbor(inEdge.edgeWeight(), inEdge.second());
| |
is assigning a neighbor to a neighbor*, are you sure this is compiling without any errors? When I make the necessary Edge class and other items and try to compile I get a whole bunch of errors in the buildGraph method.
The line numbers don't mean anything to you cause I copied it into a file graph.cpp, made an Edge class with necessary functions so I don't get warnings and then try to compile and this is what i get:
graph.cpp: In member function ‘void adjacencyList::buildGraph(Edge)’:
graph.cpp:57:14: error: no matching function for call to ‘adjacencyList::neighbor::neighbor()’
neighbor tempIt, temp2;
^
graph.cpp:57:14: note: candidates are:
graph.cpp:42:9: note: adjacencyList::neighbor::neighbor(int, int)
neighbor(int theCost, int vertex) : cost(theCost), vertexId(vertex), next(NULL){}
^
graph.cpp:42:9: note: candidate expects 2 arguments, 0 provided
graph.cpp:37:12: note: adjacencyList::neighbor::neighbor(const adjacencyList::neighbor&)
struct neighbor
^
graph.cpp:37:12: note: candidate expects 1 argument, 0 provided
graph.cpp:57:22: error: no matching function for call to ‘adjacencyList::neighbor::neighbor()’
neighbor tempIt, temp2;
^
graph.cpp:57:22: note: candidates are:
graph.cpp:42:9: note: adjacencyList::neighbor::neighbor(int, int)
neighbor(int theCost, int vertex) : cost(theCost), vertexId(vertex), next(NULL){}
^
graph.cpp:42:9: note: candidate expects 2 arguments, 0 provided
graph.cpp:37:12: note: adjacencyList::neighbor::neighbor(const adjacencyList::neighbor&)
struct neighbor
^
graph.cpp:37:12: note: candidate expects 1 argument, 0 provided
graph.cpp:62:37: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.first()-1].next = neighbor(inEdge.edgeWeight(), inEdge.second());
^
graph.cpp:64:38: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.second()-1].next = neighbor(inEdge.edgeWeight(), inEdge.first());
^
graph.cpp:73:16: error: no match for ‘operator=’ (operand types are ‘adjacencyList::neighbor’ and ‘adjacencyList::neighbor*’)
tempIt = list[inEdge.second()-1].next;
^
graph.cpp:73:16: note: candidate is:
graph.cpp:37:12: note: adjacencyList::neighbor& adjacencyList::neighbor::operator=(const adjacencyList::neighbor&)
struct neighbor
^
graph.cpp:37:12: note: no known conversion for argument 1 from ‘adjacencyList::neighbor*’ to ‘const adjacencyList::neighbor&’
graph.cpp:82:38: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.second()-1].next = tempIt;
^
graph.cpp:91:38: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.second()-1].next = neighbor(inEdge.edgeWeight(), inEdge.first());
^
graph.cpp:93:16: error: no match for ‘operator=’ (operand types are ‘adjacencyList::neighbor’ and ‘adjacencyList::neighbor*’)
tempIt = list[inEdge.first()-1].next;
^
graph.cpp:93:16: note: candidate is:
graph.cpp:37:12: note: adjacencyList::neighbor& adjacencyList::neighbor::operator=(const adjacencyList::neighbor&)
struct neighbor
^
graph.cpp:37:12: note: no known conversion for argument 1 from ‘adjacencyList::neighbor*’ to ‘const adjacencyList::neighbor&’
graph.cpp:99:37: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.first()-1].next = neighbor(inEdge.edgeWeight(), inEdge.second());
^
graph.cpp:101:37: error: cannot convert ‘adjacencyList::neighbor’ to ‘adjacencyList::neighbor*’ in assignment
list[inEdge.first()-1].next = tempIt;
^
graph.cpp:108:16: error: no match for ‘operator=’ (operand types are ‘adjacencyList::neighbor’ and ‘adjacencyList::neighbor*’)
tempIt = list[inEdge.first()-1].next;
^
...
...
...
I think you want something like this, this compiles without errors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
void adjacencyList::buildGraph(Edge inEdge)
{
neighbor *tempIt,*temp2;
if (list[inEdge.first()-1].next == NULL && list[inEdge.second()-1].next == NULL)
{
list[inEdge.first()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.second());
list[inEdge.second()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.first());
}
else if (list[inEdge.first()-1].next == NULL && list[inEdge.second()-1].next != NULL)
{
list[inEdge.first()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.second());
tempIt = list[inEdge.second()-1].next;
while(list[inEdge.second()-1].next != NULL)
{
list[inEdge.second()-1].next = list[inEdge.second()-1].next->next;
}
list[inEdge.second()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.first());
list[inEdge.second()-1].next = tempIt;
}
else if (list[inEdge.first()-1].next != NULL && list[inEdge.second()-1].next == NULL)
{
list[inEdge.second()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.first());
tempIt = list[inEdge.first()-1].next;
while(list[inEdge.first()-1].next != NULL)
{
list[inEdge.first()-1].next = list[inEdge.first()-1].next->next;
}
list[inEdge.first()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.second());
list[inEdge.first()-1].next = tempIt;
}
else
{
tempIt = list[inEdge.first()-1].next;
while(list[inEdge.first()-1].next != NULL)
{
list[inEdge.first()-1].next = list[inEdge.first()-1].next->next;
}
list[inEdge.first()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.second());
list[inEdge.first()-1].next = tempIt;
tempIt = list[inEdge.second()-1].next;
while(list[inEdge.second()-1].next != NULL)
{
list[inEdge.second()-1].next = list[inEdge.second()-1].next->next;
}
list[inEdge.second()-1].next = new neighbor(inEdge.edgeWeight(), inEdge.first());
list[inEdge.second()-1].next = tempIt;
}
}
| |