lundi 25 juillet 2016

C++ 11 to C# code Conversion issue

I am trying to convert the following C++ 11 code to C# using Visual Studio 2012,

typedef enum { _A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_1,_2,_3 }  TKeyIdentity;
typedef std::vector<TKeyIdentity const>     TKeyPath;
typedef std::vector<TKeyPath const>         TKeyMap;

const TKeyMap keyPad =
{
    { _H, _L },         // A
    { _I, _K, _M },     // B
    { _F, _J, _L, _N }, // C
    { _G, _M, _O },     // D
     { _H, _N }         // E  
}

const TKeyPath keyPadRoot =
{
    _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3
};

TraverseKeyPaths( TKeyPath const &keyPath, int pressesRemaining, int vowelsAllowed )
{
    for ( auto pressedKey: keyPath )
    {
          int value = TraverseKeyPaths(keyPad[ pressedKey ],pressesRemaining, vowelsAllowed - isVowel[pressedKey] );    
    }
}

C# Code:

enum TKeyIdentity { _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3 };
List<string> keyPadRoot = new List<string> { "_A", "_B", "_C", "_D", "_E", "_F", "_G", "_H", "_I", "_J", "_K", "_L", "_M", "_N", "_O", "_1", "_2", "_3" };

string[] A = new string[] { "_H", "_L" }; //A
string[] B = new string[] { "_I", "_K", "_M" }; //B
string[] C = new string[] { "_F", "_J", "_L", "_N" }; //C
string[] D = new string[] { "_G", "_M", "_O" }; //E

List<string> keyPadMoves = new List<string>();
keyPadMoves.AddRange(A);
keyPadMoves.AddRange(B);
keyPadMoves.AddRange(C);
keyPadMoves.AddRange(D);

int TraverseKeyPaths(List<string> keyPadRoot, int pressesRemaining, int vowelsAllowed)
{
   foreach (TKeyIdentity pressedKey in Enum.GetValues(typeof(TKeyIdentity)))
   {
      int value = TraverseKeyPaths(keyPadRoot, pressesRemaining, vowels);
   }
 }

The C# code is not working as expected. The issue is with the below line

 TraverseKeyPaths(keyPadRoot, pressesRemaining, vowels);

I need to pass first parameter as "keyPadMoves". but if I pass keyPadMoves, the recursive call goes to infinite loop

Please let me know the issue, Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire