Re: Problem in Coverting CPP code to PHP code?



On May 18, 8:37 am, dgajjanathu...@xxxxxxxxx wrote:
Hi,

this is my CPP code which i want to convert to PHP

#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include<stdio.h>
#include<conio.h>

void print_combinations( std::string prefix, const int* arr,
std::size_t N,
                         std::size_t start, std::size_t num_comb, bool
first_time = true )
{
   static std::set< std::string > prefixes ;
   if( first_time ) prefixes.clear() ;

   if( num_comb == 1 )
   {
       if( prefixes.insert(prefix).second )
       for( std::size_t i = start ; i < N ; ++i )
       {
           std::cout << prefix << arr[i] << '\n' ;
       }
   }
   else
   {

       std::string pref ;
       for( std::size_t i = start ; i < N - num_comb + 1 ; ++i )
           for( std::size_t j = i  ; j < N - num_comb + 2 ; ++j )
           {
               {
                   std::ostringstream stm( prefix ) ;
                   stm << prefix << arr[j] << " + "  ;
                   pref = stm.str() ;
               }
               print_combinations( pref, arr, N, j+1, num_comb-1,
false ) ;
           }
   }

}

int main()
{
  int arr[] = {9, 6, 3, 2} ;
  enum { N = sizeof(arr) / sizeof( arr[0] ) } ;

  for( int num_comb = 1 ; num_comb <= N ; ++num_comb )
      print_combinations( "", arr, N, 0, num_comb ) ;
      getch();

}

Please help me in solving my problem ?
how to do this??

What line(s) specifically are you having trouble with?

.