need help writing c++ version of python code

Hi I'm attempting to write the maximal clique algorithm for use with an adjacency matrix.

I'm following a video which explains how to code and implement the algorithm using python. I want to write it for c++.

This is the video : http://www.youtube.com/watch?v=SaTgYQDRkuA

I'm currently trying to code the powerset function at 2 minutes into the video.
I'm not sure if I should be using arrays or not.

So far I have coded the below but I dont know how to return an empty array inside an empty array (when the elts list is of size 0).

I wrote an isEmpty function for the array since I cant use len(elts) like in python.

My approach is probably not the best approach to take so I am open to any advice.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
bool empty = true;
bool isEmpty(int elts[])
{
    for (int z=0;z<10;z++)
    {
         if (elts[z] != 0)
         {                 
              cout << elts[z] << endl;             
              empty = false;
         }                    
    }
    if (empty == true)
    {
         //Is empty
         return (empty);
                    
    }
    else
    {
         //Is NOT empty
         return (empty);
    }        
}

array powerSet(int elts[])
{
     if (isEmpty(elts)==1)
     {
          return {{}};
     }
          
}


I don't know what to do from here.

The code should use either an array/list/vector that we call 'elts' (short for elements). Then firstly, it should add the empty list [], then the rest of the power set (all shown in the video).

So for example, in the case that elts = [1,2,3,4], my code should return:

[ [],[4],[3],[4,3],[2],[4,2],[3,2],[4,3,2],[1],[4,1],[3,1],[4,3,1],[2,1],[4,2,1],[‌​3,2,1],[4,3,2,1] ]

Thanks
Last edited on
Anyone have advice ?
This code here does what I want but I dont want to copy it straight out as I dont understand it:

http://www.cplusplus.com/forum/beginner/51164/

could anyone explain whats happening there ?

Thanks
Topic archived. No new replies allowed.