Click here to Skip to main content
12,998,654 members (130,879 online)
Click here to Skip to main content

Stats

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

Combinations in C++

, 12 Apr 2016
An article on finding combinations
#include <vector>
#include "combination.h"


template<class T>
bool FindVecComb(
	std::vector< std::vector< T > >& VecN,
	std::vector< std::vector< T > >& VecR
	)
{
	if(VecR.size() == 0)
		return false;

	size_t nDepth = VecR.size()-1;
	bool NoMore = true;
	do
	{
		NoMore = stdcomb::next_combination(	
			VecN.at(nDepth).begin(), 
			VecN.at(nDepth).end(), 
			VecR.at(nDepth).begin(), 
			VecR.at(nDepth).end() );

		if(NoMore == false)
		{
			// Initailize as before
			for( size_t i=0; i<VecR.at(nDepth).size(); ++i)
			{
				VecR.at(nDepth).at(i) = VecN.at(nDepth).at(i);
			}
		}

		if( nDepth == 0 && NoMore == false)
			return false;

		--nDepth;
	}
	while(NoMore == false);

	return true;
}

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)

  • EC-Council Certified Security Analyst (ECSA)

  • Certified Secure Software Lifecycle Professional (CSSLP)


You may also be interested in...

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