data structure question

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
void weightedGraphType::shortestPath(int vertex)
{
    for (int j = 0; j < gSize; j++)
        smallestWeight[j] = weights[vertex][j];

	bool *weightFound;
    weightFound = new bool[gSize];

    for (int j = 0; j < gSize; j++)
        weightFound[j] = false;

    weightFound[vertex] = true;
    smallestWeight[vertex] = 0;

    for (int i = 0; i < gSize - 1; i++)
    {
        double minWeight = DBL_MAX;
        int v;

        for (int j = 0; j < gSize; j++)
            if (!weightFound[j])
                if (smallestWeight[j] < minWeight)
                {
                    v = j;
                    minWeight = smallestWeight[v];
                }

        weightFound[v] = true;

        for (int j = 0; j < gSize; j++)
            if (!weightFound[j])
                if (minWeight + weights[v][j] < smallestWeight[j])
                    smallestWeight[j] = minWeight + weights[v][j];
    } //end for
} //end shortestPath 

it's always giving me infinity
that's the whole file
http://www.2shared.com/file/PAochCab/Project_7_ch12_-_3.html
g++ Main.cpp
In file included from graphType.h:16:0,
                 from weightedGraph.h:17,
                 from Main.cpp:3:
unorderedLinkedList.h: In member function ‘bool unorderedLinkedList<Type>::search(const Type&) const’:
unorderedLinkedList.h:54:15: error: ‘first’ was not declared in this scope
unorderedLinkedList.h: In member function ‘void unorderedLinkedList<Type>::insertFirst(const Type&)’:
unorderedLinkedList.h:74:21: error: ‘first’ was not declared in this scope
unorderedLinkedList.h:77:5: error: ‘count’ was not declared in this scope
unorderedLinkedList.h:79:9: error: ‘last’ was not declared in this scope
unorderedLinkedList.h: In member function ‘void unorderedLinkedList<Type>::insertLast(const Type&)’:
...


Also, just upload the sources, no need of *.obj or *.exe
what do you mean by .exe or .obj ?
I mean `Project 7 ch.12 - 3.exe', the executable. And the object files (like Main.obj)
They are useless to me.

I could compile by prefixing this-> when needed. Maybe is a compiler issue.

Now, by looking at your code, you are leaking memory and probably accessing out of bounds.
Use `std::vector' instead of manual memory managing.

Also, ¿where do you initialize `weights' ?
Topic archived. No new replies allowed.