コード例 #1
0
ファイル: ParenthesisProblem.cpp プロジェクト: kousha74/GI
void CParenthesisProblem::Test()
{
   int n = 4;
   std::cout << "Combination for n = " << n << '\n';
   PrintCombinations( n );
   std::cout << '\n';
}
コード例 #2
0
ファイル: ParenthesisProblem.cpp プロジェクト: kousha74/GI
void CParenthesisProblem::PrintCombinations( int n )
{
   char * str = (char *) malloc( 2*n + 1 );

   PrintCombinations( n, str, 0, 0 );

   free( str );
}
コード例 #3
0
ファイル: main.cpp プロジェクト: zhenl010/zhenl010
int main(int argc, char** argv)
{
    int num = 3;

    PrintBinaryAdj(num);

    PrintCombinationsAdj(num);

    PrintCombinations(num);

    return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: zhenl010/zhenl010
void PrintCombinations(std::vector<std::vector<DataType>::size_type>& outputs,
    std::vector<DataType>::size_type startIdxIn,
    const std::vector<DataType>& arrayNoDup,
    std::vector<DataType>::size_type endIdxOut)
{
    for (std::vector<DataType>::size_type idx=startIdxIn; idx<arrayNoDup.size(); ++idx)
    {
        outputs[endIdxOut++] = idx;
        PrintOut(outputs, 0, endIdxOut, arrayNoDup);
        PrintCombinations(outputs, idx+1, arrayNoDup, endIdxOut);
        --endIdxOut;
    }
}
コード例 #5
0
ファイル: ParenthesisProblem.cpp プロジェクト: kousha74/GI
void CParenthesisProblem::PrintCombinations( int n, char * str, int open, int close )
{
   if ( ( open + close ) == 2*n )
   {
      str[ 2*n ] = 0;
      std::cout << str << '\n';
      return;
   }

   // check if "(" can be added
   if ( open < n ) 
   {
      str[ open + close ] = '(';
      PrintCombinations( n, str, open + 1, close );
   }

   // check if ")" can be added
   if ( close < open  ) 
   {
      str[ open + close ] = ')';
      PrintCombinations( n, str, open , close + 1 );
   }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: zhenl010/zhenl010
void PrintAllCombinations(const std::vector<DataType>& arrayNoDup)
{
    std::vector<std::vector<DataType>::size_type> outputs(arrayNoDup.size());
    PrintCombinations(outputs, 0, arrayNoDup, 0);
}