// Copyright (C) 2004 BenBear //// This file is an algorithm of combination This library is free // software;. You can redistribute it and / or modify it under the // terms of the GNU General Public License as published By The // Free Software Foundation; Either Version 2, or (at Your Option) // Any Later Version.
// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY;. Without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the // GNU General Public License for more details.
. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING If not, write to the Free // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111- 1307,
#include #include using namespace std;
Template Inline Void__combi_reverse (Biiter First, Biiter Last) {Reverse (First, Last);
Template BOOLNEXT_CONATION_COT (Biiter First, Biiter Last) {if (first == Last) Return False; Biiter I = Last; if (--i == first) Return False; if (* i - == 0 ) {While (* i == 0)) --I; if (* i == 0) Return false; biiter j = i; ore_swap (i, j); return true WHILE ((i! = First) && (* i == 1)) --i; if (i == first) {if (* i == 0) ore_swap (first, --last); Return False } Biiter II = I; While ((- II! = First) && (* ii == 0)); if (* ii == 0) {__combi_reverse (first, last); return false;} Biiter JJ = II; Iter_Swap (II, JJ); __combi_reverse ( JJ, Last); Return True;}
Template BoolPrev_combination_count (Biiter First, Biiter Last) {if (First == Last) Return False; Biiter I = Last; IF (--i == First) Return False; While ((i! = first) && (* i == 0)) --I; if (i == first) {if (* i == 1) iter_swap (first, --last); Return False;} biiter j = i; --j; IF (* j == 0) {Iter_SWAP (i, j); return true;} while ((--j! = first) && (* j == 1)); if (* j == 1) {__combi_reverse (radurn false;} biiter jj = j; iter_swap (j, jj); __combi_reverse ( jj, last); return true;} // for testint main () {const INT n = 7 ; Int a [n]; int b [n] = {0}; int N = 3; for (int i = 0; i