###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

# Dijkstra's Algorithm implementation

C++
Hello Experts,

I am having a real dilly of a pickle here with implementing this algorithm.  I understand the basic concept on how it tries to find the shortest path from point a to c with the least amount of weight, but I believe I am coding more than I need to.

If some one could take a peek and show me what i'm doing wrong I would appreciate it.

Stuff to know:
argument s = =  0
size == 10
distance[s][u] = tells you the weight of edge
precede[s][u] = suppose to move to previous node

all() = function to test if array contains all correct bools = in this case 'false'

If I didn't make this clear enough let me know and thanks for your help!

**************************************************************
void graph::short_path_graph(int s)
{
bool * permanent;
permanent = new bool [size];

for(int x = 0; x < size; x++)
{
permanent[x] = false;
}

for(int i = 1; i < size; i++)
{
distance[s][i] = INT_MAX;
}

distance[s][s] = 0;

while(!all(permanent))
{
int u = 0;
int v = 0;

for(int i = 1; i < size; ++i)
{
for(int y = 0; y < size; y++)
{
{
if(distance[s][i] < distance[s][y] && !permanent[s])
{
v = distance[s][i];
y++;
}

}

}
}

permanent[v] = true;

for(u = 0; u < size; ++u)
{
{
if(distance[s][u] > distance[s][v] + distance[v][u])
{
distance[s][u] = distance[s][v] + distance[v][u];

precede[s][u] = v;

}

}

}

}

}

***************************************