⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmulist.cpp

📁 用c++变得一个测量财富的+游戏
💻 CPP
📖 第 1 页 / 共 5 页
字号:
MMG_LLIST_TY            *mmlEntry;
int                      mmlCmp;
int                      mmlExit;
int                      mmlCommand;

/************************* Procedure Body *****************************/
mmlErr = FAILED_;

if (numEntries == 0)
  {
  mmlErr = AppendAfterTail( pasSizeOfBuf, pasBufPtr );
  }
else
  {
  mmlEntry     = head;
  mmlExit      = FALSE_;
  mmlCommand   = MML_INSERT_AT_HEAD;
  while (mmlExit == FALSE_)
    {
    mmlCmp = pasFncCompare( pasBufPtr, mmlEntry->buf.body );
    if (mmlCmp >= 0)
      {
      mmlExit     = TRUE_;
      mmlCommand  = MML_INSERT_AT_CURRENT;
      current     = mmlEntry;
      }
    else
      {
      mmlEntry = mmlEntry->next;
      if (mmlEntry == NULL)
        {
        mmlExit = TRUE_;
        mmlCommand = MML_INSERT_AT_TAIL;
        }
      }
    }
  if (mmlCommand == MML_INSERT_AT_HEAD)
    {
    mmlErr = InsertBeforeHead( pasSizeOfBuf, pasBufPtr );
    }
  else if (mmlCommand == MML_INSERT_AT_CURRENT)
    {
    mmlErr = InsertBeforeCurrent( pasSizeOfBuf, pasBufPtr );
    }
  else // MML_INSERT_AT_TAIL
    {
    mmlErr = AppendAfterTail( pasSizeOfBuf, pasBufPtr );
    }
  }

return(mmlErr);
} /* MMUllist::InsertSorted end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::InsertSorted

    PURPOSE:  to insert a record sorted, based on the user's
      "compare" function pointer



**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlErr             FNC    (SUCCEEDED_ / FAILED_) error return    **
**\p*******************************************************************/

STAT_TYPE MMUllist::InsertSorted
( int (* pasFncCompare) (const void *pasStru1,
                         const void *pasStru2 ),
  MMP_DATA_TY &pasEntry )

{ /* MMUllist::InsertSorted procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/

/************************* Procedure Body *****************************/

return( InsertSorted( pasFncCompare, pasEntry.size, pasEntry.body ));

} /* MMUllist::InsertSorted end */


/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::FindFirstEntry

    PURPOSE:  to find the first ocurrence of an entry in the list.
      The caller provides the address of a function that performs
      the comparison.  We step through the list, starting at
      the head, performing the compare. When the compare returns
      a 0, we return the current datum pointer.  If end of list
      is reached first, return a NULL.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlDatum           FNC    MMP_DATA_TY *, addr of matched value   **
**\p*******************************************************************/

MMP_DATA_TY *MMUllist::FindFirstEntry
( int (* pasFncCompare) (const void *pasStru1,
                         const void *pasStru2 ),
  void  *pasBufPtr,
  INT32 &refIndexFound )

{ /* MMUllist::FindFirstEntry procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
MMG_LLIST_TY            *mmlEntry;
MMP_DATA_TY             *mmlDatum;
int                      mmlExit;
int                      mmlCmp;
/************************* Procedure Body *****************************/
mmlDatum        = NULL;
refIndexFound   = -1L;

if (pasBufPtr != NULL)
  {
  if (numEntries == 1)
    {
    mmlDatum = First();
    mmlCmp = pasFncCompare( (void*)mmlDatum->body, pasBufPtr );
    if (mmlCmp != 0) mmlDatum = NULL;
    else             refIndexFound = 0L;
    }
  else if (numEntries > 1)
    {
    mmlEntry     = head;
    refIndexFound= 0L;
    mmlExit      = FALSE_;
    while (mmlExit == FALSE_)
      {
      mmlCmp = pasFncCompare( pasBufPtr, mmlEntry->buf.body );
      if (mmlCmp == 0)
        {
        mmlExit     = TRUE_;
        mmlDatum    = &mmlEntry->buf;
        }
      else
        {
        mmlEntry = mmlEntry->next;
        refIndexFound++;
        if (mmlEntry == NULL)
          {
          mmlExit       = TRUE_;
          refIndexFound = -1L;
          }
        }
      }
    }
  }

if (mmlDatum != NULL)
  {
  current = mmlEntry;
  }

return(mmlDatum);
} /* MMUllist::FindFirstEntry end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::FindFirstEntry

    PURPOSE:  to find the first ocurrence of an entry in the list.
      The caller provides the address of a function that performs
      the comparison.  We step through the list, starting at
      the head, performing the compare. When the compare returns
      a 0, we return the current datum pointer.  If end of list
      is reached first, return a NULL.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlDatum           FNC    MMP_DATA_TY *, addr of matched value   **
**\p*******************************************************************/

MMP_DATA_TY *MMUllist::FindFirstEntry
( int (* pasFncCompare) (const void *pasStru1,
                         const void *pasStru2 ),
  void  *pasBufPtr )

{ /* MMUllist::FindFirstEntry procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
INT32                   mmlBurnIt;
MMP_DATA_TY            *mmlDatum;

/************************* Procedure Body *****************************/

mmlDatum = FindFirstEntry( pasFncCompare, pasBufPtr, mmlBurnIt );

return(mmlDatum);

} /* MMUllist::FindFirstEntry end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::FindNextEntry

    PURPOSE:  to find the next ocurrence of an entry in the list.
      The caller provides the address of a function that performs
      the comparison.  We step through the list, starting at
      the current->next entry, performing the compare. When the compare
      returns a 0, we return the current datum pointer.  If end of list
      is reached first, return a NULL.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlDatum           FNC    MMP_DATA_TY *, addr of matched value   **
**\p*******************************************************************/

MMP_DATA_TY *MMUllist::FindNextEntry
( int (* pasFncCompare) (const void *pasStru1,
                         const void *pasStru2 ),
  void  *pasBufPtr )

{ /* MMUllist::FindNextEntry procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
MMG_LLIST_TY            *mmlEntry;
MMP_DATA_TY             *mmlDatum;

int                      mmlExit;
int                      mmlCmp;
/************************* Procedure Body *****************************/
mmlDatum        = NULL;
if (numEntries > 0)
  {
  mmlEntry     = current->next;
  if (mmlEntry != NULL)
    {
    mmlExit      = FALSE_;
    while (mmlExit == FALSE_)
      {
      mmlCmp = pasFncCompare( pasBufPtr, mmlEntry->buf.body );
      if (mmlCmp == 0)
        {
        mmlExit     = TRUE_;
        mmlDatum    = &mmlEntry->buf;
        }
      else
        {
        mmlEntry = mmlEntry->next;
        if (mmlEntry == NULL)
          {
          mmlExit = TRUE_;
          }
        }
      }
    }
  }

if (mmlDatum != NULL)
  {
  current = mmlEntry;
  }

return(mmlDatum);
} /* MMUllist::FindNextEntry end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::FindNextEntry

    PURPOSE:  to find the next ocurrence of an entry in the list.
      The caller provides the address of a function that performs
      the comparison.  We step through the list, starting at
      the current->next entry, performing the compare. When the compare
      returns a 0, we return the current datum pointer.  If end of list
      is reached first, return a NULL.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlDatum           FNC    MMP_DATA_TY *, addr of matched value   **
**\p*******************************************************************/

MMP_DATA_TY *MMUllist::FindNextEntry
( int (* pasFncCompare) (const void *pasStru1,
                         const void *pasStru2 ),
  void  *pasBufPtr,
  INT32 &refIndexFound )

{ /* MMUllist::FindNextEntry procedure */

/******************* Local Constant Declarations **********************/

/******************* Local Variable Declarations **********************/
MMP_DATA_TY             *mmlDatum;
/************************* Procedure Body *****************************/

refIndexFound   = -1L;
mmlDatum        = FindNextEntry( pasFncCompare, pasBufPtr );

if (mmlDatum != NULL)
  {
  refIndexFound = GetIndexOfCurrent();
  }

return(mmlDatum);
} /* MMUllist::FindNextEntry end */

/*\p********************************************************************
**                                                                    **
**                                                                    **
    NAME:  MMUllist::GetIndexOfCurrent

    PURPOSE:  to get the numerical index of the current entry.
      This can be SLOW.  That is, this package does not maintain
      an index of the current entry....for speed considerations.
      However, sometimes you want to know the "n'th" position of
      the current entry.  This guy can find it.  It uses
      pointer comparisons, so it isn't too bad.  If it is VERY
      IMPORTANT to maintain a current index to the current
      entry, then add it to the private: portion of this class
      and modify ALL member functions which modify the 'current'
      entry. Return -1 if empty list or other error.

**                                                                    **
**                                                                    **
**  INTERFACE DEFINITION:                                             **
**     variable         def.          expected/description            **
**   ------------       -----  -------------------------------------  **
**   mmlInx             FNC    INT32, index of current entry          **
**\p*******************************************************************/

INT32 MMUllist::GetIndexOfCurrent()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -