Click here to Skip to main content
11,630,646 members (81,152 online)
Click here to Skip to main content
Add your own
alternative version

Combinations in C++

, 13 Sep 2009 CPOL 206.1K 4.7K 58
An article on finding combinations.
//This recv_comb_ex.cpp tests the recursive combination function out
#include<iostream>
#include<vector>
#include<string>
#include"combination.h"

using namespace std;
using namespace stdcomb;


//test recursive_combination() with pointers

void display(char* begin,char* end)
{
  cout<<begin<<endl;
}
int main()
{
  char ca[]="123456";
  char cb[]="1234";
   
  recursive_combination(ca,ca+6,0,
                  cb,cb+4,0,6-4,display);
  cout<<"Complete!"<<endl;
	return 0;
}


/*
//test recursive_combination() with iterator
typedef vector<int>::iterator vii;

void display(vii begin,vii end)
{
  for (vii it=begin;it!=end;++it)
      cout<<*it;
  cout<<endl;
}

int main()
{
  vector<int> ca;
  ca.push_back (1);
  ca.push_back (2);
  ca.push_back (3);
  ca.push_back (4);
  ca.push_back (5);
  ca.push_back (6);
  vector<int> cb;
  cb.push_back (1);
  cb.push_back (2);
  cb.push_back (3);
  cb.push_back (4);
   
  recursive_combination(ca.begin (),ca.end(),0,
                  cb.begin(),cb.end(),0,6-4,display);
  cout<<"Complete!"<<endl;
	return 0;
}
*/

/*
//test recursive_combination() with array of strings

void display(string* begin,string* end)
{
  for (string* it=begin;it!=end;++it)
      cout<<*it<<" ";
  cout<<endl;
}


int main()
{
  string* strarray=new string[3];
  strarray[0]="Red";
  strarray[1]="Green";
  strarray[2]="Blue";
  string* strarray1=new string[2];
  strarray1[0]="Red";
  strarray1[1]="Green";
  
  recursive_combination(strarray,strarray+3,0,
                  strarray1,strarray1+2,0,3-2,display);
  cout<<"Complete!"<<endl;
  delete [] strarray;
  delete [] strarray1;

	return 0;
  
}
*/

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shao Voon Wong
Software Developer
Singapore Singapore
IT Certifications

  • IT Infrastructure Library Foundational (ITIL v3)
  • Scrum Alliance Certified Scrum Master (CSM)
  • EC-Council Certified Secure Programmer (ECSP) .NET
  • EC-Council Certified Ethical Hacker (CEH)
  • EC-Council Certified Security Analyst (ECSA)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150723.1 | Last Updated 13 Sep 2009
Article Copyright 2003 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid