When you post code, you should identify where the problem is - what is working and what isn't - and then ask for help regarding that specific problem. Posting code and saying "Output is supposed to be A but it is B" doesn't help me as much as it has helped you to understand where the problem is. This is especially true when the output has nothing to do with syntax but everything to do with your logic.
And then to add salt your have basically requested for someone to write the code for you. tsk tsk.
I am just going with keywords here to identify what you need help with. So you are trying to implement a minimum spanning tree algorithm - Prim's algorithm to be exact. Well a quick search on google has revealed pseudocode for this algorithm: http://en.wikipedia.org/wiki/Prim's_algorithm
Also note that the area in the pseudocode that says `u = Extract-Min(Q)` requires the use of a heap data structure if you want the algorithm to be reasonably fast for large input.
logic is right but result isn't, i cant identify the problem so i have to post all the code... It easier for you to check from the beginning to the end! right?
If i know where the problem, it will post the problem only. why i have to post the long long code like that???? i have thought before i post it---
@Smac89
OP has done nothing wrong. He has posted his (short!) code, explained exactly what the problem is (reporting invalid edge), and asked for help regarding that specific problem.
Programming comes in two parts. If all user problems were just a matter of syntax we members of the forum would be obviated. The problem is his logic, which is exactly where he is having a problem, and what he has asked us to help with.
And he never asked anyone to write code for him.
Also, you are sidestepping his problem by looking up Wikipedia instead of understanding his algorithm. Just because it is "Prim's" doesn't mean there aren't multiple ways to handle it. Part of the point of Prim's is that you don't need any particularly fancy data structures to handle it. Adding a heap to the mix increases complexity unnecessarily.
@nightmaregiba
Sorry, I haven't had time to look at your code until now, but ne555 has already identified the errors for you.
Error 1:
The graph, the way it is described (in the adjacency matrix), means that it is possible to have an edge of any weight except zero. This is why ne555 specifically asked you about it.
Frankly, I don't think there's much you can do about it, since it is part of your assignment, alas. Just continue to assume that an edge of weight zero is the same as saying 'no edge'.
Error 2:
On line 46 you have forgotten the last issue -- an edge of weight zero means 'no edge'. In addition to your existing condition, you must also make sure that the edge (u,v) is not zero. (Because if it is, there really isn't an edge there.)
Fix that, and you'll see the correct output.
ne555 is sometimes difficult to understand because he doesn't waste many words, but he is very intelligent and often asks questions that are designed to lead you to find the answer for yourself.