Question: can you help me fix this syntax error, dont use vectors only dynamically allocated arrays. Also the function needs to be in the edge class

can you help me fix this syntax error, dont use vectors only dynamically allocated arrays. Also the function needs to be in the edge class provided according to instructions. Can you help me figure this out
dijkstra.h:
2
4
7
:
3
5
: error:
const class graph
has no member named
getNeighbor
2
4
7
|
for
(
const auto &edge : g
.
getNeighbor
(
u
.
vertexNum
)
)
{
|
void DijkstraShortestPath
(
const graph &g
,
int start
)
{
int numVertices
=
g
.
getNumVer
(
)
;
minHeap minHeap
(
numVertices
)
;
/
/
assuming minHeap can be constructed with the number of vertices
int
*
locator
=
new int
[
numVertices
]
;
/
/
Dynamic array for locator
/
/
Initialize all vertices
for
(
int i
=
0
; i
<
numVertices;
+
+
i
)
{
vertex ver;
ver.vertexNum
=
i;
ver.curDist
=
9
9
9
;
ver.predecessor
=
-
1
;
minHeap.insert
(
ver
)
;
locator
[
i
]
=
i;
/
/
Locator initialization
}
/
/
Update the start vertex in the heap
vertex startVertex
=
minHeap.getElem
(
locator
[
start
]
)
;
startVertex.curDist
=
0
;
minHeap.updateElem
(
locator
[
start
]
,
startVertex
)
;
/
/
Dijkstra's algorithm main loop
while
(
!
minHeap.isEmpty
(
)
)
{
vertex u
=
minHeap.getMin
(
)
;
int uIndex
=
locator
[
u
.
vertexNum
]
;
for
(
const auto &edge : g
.
getNeighbor
(
u
.
vertexNum
)
)
{
int v
=
edge.first;
int weight
=
edge.second;
int vIndex
=
locator
[
v
]
;
if
(
u
.
curDist
+
weight
<
minHeap.getElem
(
vIndex
)
.
curDist
)
{
vertex vVertex
=
minHeap.getElem
(
vIndex
)
;
vVertex.curDist
=
u
.
curDist
+
weight;
vVertex.predecessor
=
u
.
vertexNum;
minHeap.updateElem
(
vIndex
,
vVertex
)
;
}
}
}
/
/
Clean up the dynamic array
delete
[
]
locator;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!