I am a kind of still learning about C++ and I just have some kind of error message on my code telling me that undeclared identifier error code c2065. I am trying to figure out where my error is and how to fix it. I kind of know what my error but, I just don't know how to fix it. Thanks for the help.
Here is my code
#include <iostream>
typedef struct NodeType {
char name; // the node's name
int weight; // the node's current weight
int pi; // the node's parent
} Node;
int graph[6][6] = {
{0,1,2,0,0,0},
{1,0,5,9,0,10},
{2,5,0,3,0,0},
{0,9,3,0,3,0},
{0,0,0,3,0,2},
{0,10,0,0,2,0}
};
Node node[6];
bool visited[6];
int getMinNode()
{
int index = -1;
for (int i=0; i<6; i++)
{
if (!visited[i])
{
index = i;
break;
}
}
for (int j=i+1; j<6; j++)
{
if (node[j].weight < node[index].weight) index = j;
}
return index;
}
void printResult(char *message) {
printf("%s\n", message);
for (int i=0; i<6; i++) {
if (node[i].pi >= 0) {
int parent = node[i].pi;
printf("%c -- %c \n", node[i].name, node[parent].name);
}
}
}
int main() { // Prim's algorithm
// Initialize the 6 nodes
for (int i=0; i<6; i++) {
node[i].name = 'A'+i;
node[i].pi = -1; // no parent
node[i].weight = 10000; // 10000 as infinity
visited[i] = false;
}
// Start from node 'A'
node[0].weight = 0;
int index = getMinNode();
// Prim's algorithm
while (index >= 0) {
visited[index] = true;
for (int j=0; j<6; j++) {
if (j==index) continue;
if (graph[j][index] == 0) continue;
int weight = node[index].weight + graph[j][index];
if (weight < node[j].weight) {
node[j].weight = weight;
node[j].pi = index;
}
}
index = getMinNode();
}
// Print out the result
printResult("Final Minimum Spanning Tree:");
}
MOD EDIT: When posting code...USE CODE TAGS!!!
Also, post in the RIGHT forum...Site Feedback is NOT for C++ Questions. Moved to C and C++.
This post has been edited by JackOfAllTrades: 19 December 2010 - 11:08 AM

New Topic/Question
Reply




MultiQuote








|