1

Background to the problem:

Im currently working on a pathfinder. My lastest implementation was the ability to load in different mapfiles instead of only using one array containing the map. So before it looked like this:

Node[] mMatrix;

However since I want to load in different segments of nodes. I made this:

List<Node[]>

The class, Node simply contains an int declared as F.

And now to the issue!

To be short, the specific question is how would you compare an object of type : List< Node[] > in the IComparer Members Compare method.

I have been using a priorityQueue for speeding up the pathfinder algorithm but now Im having issues with comparing this new "2 dimensional" datastructure. For my old working implementation i used this:

internal class ComparePFNodeMatrix : IComparer<int>
{
    //Variables Declaration
    Node[] mMatrix;

    //Constructors
    public ComparePFNodeMatrix(Node[] matrix)
    {
        mMatrix = matrix;
    }

    //IComparer Members
    public int Compare(int a, int b)
    {
        if (mMatrix[a].F > mMatrix[b].F)
            return 1;
        else if (mMatrix[a].F < mMatrix[b].F)
            return -1;
        return 0;
    }
}

Anyone knowing how to make a comparer with the new datastructure Im using? Thanks on advance!

LamaCoder
  • 223
  • 1
  • 18
  • you get list `List n2 = (List)b;` and try get field `F ` from list, `n1.F` this `n1` is List, not Node – Grundy Nov 26 '13 at 09:01
  • [Please do not put tags in your question title.](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles) – O. R. Mapper Nov 26 '13 at 09:02
  • 1
    To implement `IComparer`, you need a `Compare(int, int)` method, which makes your new Compare method completely useless. You probably need to operate on a different level; after all how can you simply compare two lists of arrays of objects? It looks like a quite complex issue. – S_F Nov 26 '13 at 09:09
  • Allright! Thank you very much. Do you have any recommendations of what appraoch I should use? I do certainly agree with you that it is a complex issue. – LamaCoder Nov 26 '13 at 15:07

1 Answers1

0

You said you have changed Node[] mMatrix; to List<Node[]> mMatrix;. If that's the case,

mMatrix[a] gives you the Node[] and not the Node.
If you want to access F you have to use something like:

int i = (mMatrix[a])[anotherIndex].F;

EDIT 1:
And if you are using List<Node[]> n1 = (List<Node[]>)a; then how can you access F with simply n1.F? n1 is of type List<Node[]> and not Node. It's as straightforward as it can get.

Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32
  • Certainly! The issue now is then, how do I make a Priorityqueue support a kind of 2D array? I bet it´s not possible using the compare method since it only has 2 parameters? – LamaCoder Nov 26 '13 at 15:19