get all combinations

// new a vector
Vector<char> combin = new Vector<char>();
public void combination( char str[], int start, Vector<char> vc )
{
    if( str == null && str.length <= 0 )
    {
        return;
    }

    if( start == str.length -1 )
    {
        vc.add( str[start] );
        combin.add( vc );
        System.out.println( combin.toString() );
        // recursive terminated and return
        return;
    }
    for( int i = start; i < str.length; i++ )
    {
        vc.add( str[start] );
        combin.add( vc );
        System.out.println( combin.toString() );
        combination( str, start + 1, vc );
    }
}

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s