source: ntrip/trunk/BNC/src/bnccomb.h@ 4295

Last change on this file since 4295 was 4278, checked in by mervart, 12 years ago
File size: 1.4 KB
Line 
1
2#ifndef BNCCOMB_H
3#define BNCCOMB_H
4
5template <class BidIt>
6inline bool next_combination(BidIt n_begin, BidIt n_end,
7 BidIt r_begin, BidIt r_end) {
8
9 bool boolmarked=false;
10 BidIt r_marked;
11
12 BidIt n_it1=n_end;
13 --n_it1;
14
15
16 BidIt tmp_r_end=r_end;
17 --tmp_r_end;
18
19 for(BidIt r_it1=tmp_r_end; r_it1!=r_begin || r_it1==r_begin; --r_it1,--n_it1)
20 {
21 if(*r_it1==*n_it1 )
22 {
23 if(r_it1!=r_begin) //to ensure not at the start of r sequence
24 {
25 boolmarked=true;
26 r_marked=(--r_it1);
27 ++r_it1;//add it back again
28 continue;
29 }
30 else // it means it is at the start the sequence, so return false
31 return false;
32 }
33 else //if(*r_it1!=*n_it1 )
34 {
35 //marked code
36 if(boolmarked==true)
37 {
38 //for loop to find which marked is in the first sequence
39 BidIt n_marked;//mark in first sequence
40 for (BidIt n_it2=n_begin;n_it2!=n_end;++n_it2)
41 if(*r_marked==*n_it2) {n_marked=n_it2;break;}
42
43
44 BidIt n_it3=++n_marked;
45 for (BidIt r_it2=r_marked;r_it2!=r_end;++r_it2,++n_it3)
46 {
47 *r_it2=*n_it3;
48 }
49 return true;
50 }
51 for(BidIt n_it4=n_begin; n_it4!=n_end; ++n_it4)
52 if(*r_it1==*n_it4)
53 {
54 *r_it1=*(++n_it4);
55 return true;
56 }
57 }
58 }
59
60 return true;//will never reach here
61}
62
63#endif
Note: See TracBrowser for help on using the repository browser.