Click here to Skip to main content
16,016,301 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What does this syntax mean in c++ ? Pin
CPallini4-Oct-09 6:22
mveCPallini4-Oct-09 6:22 
GeneralRe: What does this syntax mean in c++ ? Pin
holyinferno4-Oct-09 6:26
holyinferno4-Oct-09 6:26 
AnswerRe: What does this syntax mean in c++ ? Pin
David Crow5-Oct-09 4:48
David Crow5-Oct-09 4:48 
QuestionGood code, wrong result Pin
Waldemar Ork4-Oct-09 4:56
Waldemar Ork4-Oct-09 4:56 
AnswerRe: Good code, wrong result Pin
Luc Pattyn4-Oct-09 5:25
sitebuilderLuc Pattyn4-Oct-09 5:25 
AnswerRe: Good code, wrong result Pin
Richard MacCutchan4-Oct-09 5:44
mveRichard MacCutchan4-Oct-09 5:44 
GeneralRe: Good code, wrong result Pin
Luc Pattyn4-Oct-09 6:08
sitebuilderLuc Pattyn4-Oct-09 6:08 
GeneralRe: Good code, wrong result Pin
Waldemar Ork4-Oct-09 7:40
Waldemar Ork4-Oct-09 7:40 
Your remark about GetNextCombination function is precious. I think I should modify the header file. What I think of is to apply somehow the rule "one element past the last". This should help.
Anyway here's the header file with GetNextCombination function if you'd like to have a look at it :
#include "IndexCombination.h"

using namespace stdcomb;


void CIdxComb::Init( unsigned int SetSize, unsigned int CombSize   )
{
     // Assign CombSize
     ////////////////////////
     if( CombSize == 0 )
          CombSize = 1;

     m_ArrSize = CombSize;
     m_LastIdx = CombSize - 1;

     // Assign SetSize
     ////////////////////////
     if( SetSize == 0 )
          SetSize = 2;

     if( CombSize > SetSize )
          CombSize = SetSize;
    
     m_SetSize = SetSize;
     m_LastSetIdx = SetSize - 1;
}


bool CIdxComb::SetSizes( unsigned int SetSize, unsigned int CombSize )
{
     if( SetSize == 0 )
          return false;

     if( CombSize == 0 )
          return false;

     if( CombSize > SetSize )
          return false;
    
     m_ArrSize = CombSize;
     m_LastIdx = CombSize - 1;

     m_SetSize = SetSize;
     m_LastSetIdx = SetSize - 1;

     return true;

}


bool CIdxComb::GetNextComb( std::vector<unsigned int> &vi )
{
    
     // Check if the last element is at the end
     if( vi[m_LastIdx] == m_LastSetIdx )
     {
          if( m_ArrSize == 1 ) // Completed
               return false;

          // Check if the subsequent elements(counted from back)
          // is also at their subsequent positions
          //////////////////////////////////////////////////////
          bool Completed = true;
          // Incomplete Index, init value not used
          unsigned int IncompIdx = m_LastIdx - 1;
         
          bool FirstIdx = false;
          unsigned int ArrIdx = m_LastIdx - 1;

          unsigned int SetIdx = m_LastSetIdx - 1;
         
          while( !FirstIdx )
          {
               if( vi[ArrIdx] != SetIdx )
               {
                    Completed = false;
                    IncompIdx = vi[ArrIdx] + 1;
                    break;
               }

               if( SetIdx )
                    --SetIdx;
         
               if( !ArrIdx )
                    FirstIdx = true;
               else
                    --ArrIdx;
                   
          }

          if( Completed )
               return false;
          else
          {
               for( unsigned int i=ArrIdx; i<=m_LastIdx; ++i, ++IncompIdx )
               {
                    vi[i] = IncompIdx;
               }
          }
    
     }
     else if ( vi[m_LastIdx] < m_LastSetIdx )
     {
          (vi[m_LastIdx])++;
     }
     else // bigger than the m_LastIdx! Impossible!
     {
          return false;
     }
    
     return true;
}
GeneralRe: Good code, wrong result Pin
Luc Pattyn4-Oct-09 8:39
sitebuilderLuc Pattyn4-Oct-09 8:39 
AnswerRe: Good code, wrong result Pin
David Crow5-Oct-09 4:56
David Crow5-Oct-09 4:56 
GeneralRe: Good code, wrong result Pin
Waldemar Ork5-Oct-09 23:29
Waldemar Ork5-Oct-09 23:29 
QuestionC++ Helper Wanted Pin
MrMcIntyre4-Oct-09 3:48
MrMcIntyre4-Oct-09 3:48 
QuestionRe: C++ Helper Wanted Pin
Maximilien4-Oct-09 4:11
Maximilien4-Oct-09 4:11 
AnswerRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 4:20
MrMcIntyre4-Oct-09 4:20 
GeneralRe: C++ Helper Wanted Pin
Michael Schubert4-Oct-09 4:51
Michael Schubert4-Oct-09 4:51 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 4:54
MrMcIntyre4-Oct-09 4:54 
GeneralRe: C++ Helper Wanted Pin
Michael Schubert4-Oct-09 5:08
Michael Schubert4-Oct-09 5:08 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 5:14
MrMcIntyre4-Oct-09 5:14 
GeneralRe: C++ Helper Wanted Pin
Michael Schubert4-Oct-09 5:19
Michael Schubert4-Oct-09 5:19 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 5:23
MrMcIntyre4-Oct-09 5:23 
GeneralRe: C++ Helper Wanted Pin
Michael Schubert4-Oct-09 5:34
Michael Schubert4-Oct-09 5:34 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 5:39
MrMcIntyre4-Oct-09 5:39 
GeneralRe: C++ Helper Wanted Pin
Maximilien4-Oct-09 5:58
Maximilien4-Oct-09 5:58 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 6:09
MrMcIntyre4-Oct-09 6:09 
GeneralRe: C++ Helper Wanted Pin
MrMcIntyre4-Oct-09 7:11
MrMcIntyre4-Oct-09 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.