30 for (
int i=0; i<
N; i++)
31 cout<<visited[i]<<
", ";
33 cout<<
"a\tb\tc\td\te\tf\tg\th\ti\tj";
35 cout<<
"a\tb\tc\td\te\tf\tg\th\ti\tj"<<endl;
36 cout<<
"1\t2\t3\t4\t5\t6\t7\t8\t9\t10";
38 cout<<
"1\t2\t3\t4\t5\t6\t7\t8\t9\t10"<<endl;
39 for (
int i=0; i<
N; i++) {
40 for (
int j=0; j<
N; j++)
41 cout<<pathLengths[i][j]<<
'\t';
43 for (
int j=0; j<
N; j++)
44 cout<<lastLoc[i][j]<<
'\t';
60 pathLengths =
new int*[
N];
62 cerr<<
"couldn't create path lengths"<<endl;
65 for (
int i=0; i<
N; i++)
68 for (
int i=0; i<
N; i++) {
69 pathLengths[i] =
new int[
N];
70 if (!pathLengths[i]) {
71 cerr<<
"couldn't create path lengths"<<endl;
75 roadLengths =
new int *[
N];
77 cerr<<
"couldn't create road lengths"<<endl;
80 for (
int i=0; i<
N; i++)
83 for (
int i=0; i<
N; i++) {
84 roadLengths[i] =
new int[
N];
85 if (!roadLengths[i]) {
86 cerr<<
"couldn't create road lengths"<<endl;
91 lastLoc =
new int *[
N];
93 cerr<<
"couldn't create last lengths"<<endl;
96 for (
int i=0; i<
N; i++)
99 for (
int i=0; i<
N; i++) {
100 lastLoc[i] =
new int[
N];
102 cerr<<
"couldn't create last lengths"<<endl;
107 visited =
new int [
N];
109 cerr<<
"couldn't create visited"<<endl;
116 for (
int i=0; i<
N; i++) {
117 if (pathLengths[i]) {
118 delete [] pathLengths[i];
128 for (
int i=0; i<
N; i++) {
129 if (roadLengths[i]) {
130 delete [] roadLengths[i];
139 for (
int i=0; i<
N; i++) {
141 delete [] lastLoc[i];
155 for (
int i=0; i<
N; i++)
159 pathLengths[i][j]=pl;
162 roadLengths[i][j]=pl;
170 unsigned int lastLength;
171 for (
int j=0; j<
N; j++)
172 pathLengths[0][j]=roadLengths[0][j];
174 for (
int i=1; i<
N; i++) {
175 for (
int j=0; j<
N; j++)
176 pathLengths[i][j]=pathLengths[i-1][j];
178 lastLength=pathLengths[i-1][i];
179 for (
int j=0; j<
N; j++)
180 if (!visited[j] & i!=j) {
181 if (lastLength+roadLengths[i][j]<pathLengths[i-1][j]) {
182 pathLengths[i][j]=lastLength+roadLengths[i][j];
191 #endif // DIJKSTRA_H_
void setLastLoc(int pl, int i, int j)
void setRoadLengths(int pl, int i, int j)
void dumpArrays(int **roadLengths, int Nin)
void setPathLengths(int pl, int i, int j)
void setVisited(int *vis)