/* Sorts the items in the list. While sorting, it calls the specified callback function which should do the actual comparison of the items.  */
void TbxListSortItems(tTbxList const *list, tTbxListCompareItems compareItemsFcn)
/* Sorts the items in the list. While sorting, it calls the specified callback function which should do the actual comparison of the items.  */
void TbxListSortItems(tTbxList const *list, tTbxListCompareItems compareItemsFcn)
{
  tTbxListNode * currentNode;
  tTbxListNode * idxNode;
  void         * tempItemPtr;
  TBX_ASSERT(list != NULL);
  TBX_ASSERT(compareItemsFcn != NULL);
  if ( (list != NULL) && (compareItemsFcn != NULL) )
  {
    TbxCriticalSectionEnter();
    currentNode = list->firstNodePtr;
    while (currentNode->nextNodePtr != NULL)
    {
      idxNode = currentNode->nextNodePtr;
      while (idxNode != NULL)
      {
        if (compareItemsFcn(currentNode->itemPtr, idxNode->itemPtr) == TBX_TRUE)
        {
          tempItemPtr = currentNode->itemPtr;
          currentNode->itemPtr = idxNode->itemPtr;
          idxNode->itemPtr = tempItemPtr;
        }
        idxNode = idxNode->nextNodePtr;
      }
      currentNode = currentNode->nextNodePtr;
    }
    TbxCriticalSectionExit();
  }
}