SquishyChs wrote: |
---|
This is the main class: |
No, it's not, it's the .cpp file with the main
function in it. Not even Java has such a thing as a "main class" ;)
SquishyChs wrote: |
---|
Graph<Position>* graphy = new Graph<Position>(); |
Why is this a pointer? You don't need to use pointers or dynamic allocation/deallocation here.
SquishyChs wrote: |
---|
float distance = sqrt(sqrt(pow(diff.x, 2) + pow(diff.y, 2)) + pow(diff.z, 2)); |
I'd like to know where you learned the distance formula, because this doesn't look like it to me. See
http://en.wikipedia.org/wiki/Distance_formula#Geometry - the third one is for 3D distance.
SquishyChs wrote: |
---|
int numNodes; |
This is wrong; LinkedList should keep track of the number of elements it has, not Graph. Graph should just ask LinkedList how many elements it has.
SquishyChs wrote: |
---|
LinkedList<GraphNode<T>*>* nodes; |
Again, you don't need pointers here. A
LinkedList<GraphNode<T> >
would be better. Your functions should probably return and take references too.
SquishyChs wrote: |
---|
LinkedList<GraphNode<T>*>* connections; |
Looking at this, I think you have your design wrong. This is a nightmare waiting to happen, because it means you have too many places to manage pinters. But you've already got it set up like this, I think it'd be a waste of time to change it. Just don't do this kind of thing in the future ;)
There are a multitude of problems with this code but I think your main problem is that insane distance formula. You've done very well with all this, though, and I think you've got the right general ideas. Just don't use pointers when you don't need them. LinkedList is the only class that needs to use pointers to its data, for obvious reasons, but the other places could do without pointers since they don't really utilize the actual features of pointers.