Click here to Skip to main content
13,000,469 members (62,144 online)
Click here to Skip to main content

Stats

243K views
5.3K downloads
68 bookmarked
Posted 12 Apr 2016

Combinations in C++

, 12 Apr 2016
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"


// for use with next_combination examples!
template<class BidIt>
void display(BidIt begin,BidIt end)
{
  for (BidIt it=begin;it!=end;++it)
      cout<<*it<<" ";
  cout<<endl;
}


using namespace std;
using namespace stdcomb;



//test next_combination() with pointers

int main()
{
  char ca[]="123456";
  char cb[]="1234";
   
  do
  {
    cout<<cb<<endl;
  }
  while(next_combination(ca,ca+6,cb,cb+4));
  cout<<"Complete!"<<endl;
  
  return 0;
}


/*
//test next_combination() with iterators
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);
   
  do
  {
    display(cb.begin(),cb.end());
  }
  while(next_combination(ca.begin (),ca.end (),cb.begin (),cb.end()) );
  
  cout<<"Complete!"<<endl;
  
  return 0;
}
*/

/*
//test next_combination() with strings
int main()
{
  vector<string> str;
  str.push_back ("Red");
  str.push_back ("Green");
  str.push_back ("Blue");
  vector<string> str1;
  str1.push_back ("Red");
  str1.push_back ("Green");
   
  do
  {
    display(str1.begin(),str1.end());
  }
  while(next_combination(str.begin (),str.end (),str1.begin (),str1.end()));

  cout<<"Complete!"<<endl;
  
	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

Cake Processor
Software Developer (Senior)
United States United States
IT Certifications


  • IT Infrastructure Library Foundational (ITIL v3)

  • Scrum Alliance Certified Scrum Master (CSM)

  • Certified Secure Software Lifecycle Professional (CSSLP)


You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Cake Processor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid