Click here to Skip to main content
12,630,455 members (30,085 online)
Click here to Skip to main content

Stats

234.5K views
5.2K downloads
68 bookmarked
Posted

Combinations in C++

, 12 Apr 2016 CPOL
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 (Senior)
United States United States
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)
  • Certified Secure Software Lifecycle Professional (CSSLP)

You may also be interested in...

Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 12 Apr 2016
Article Copyright 2016 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid