本文整理汇总了C++中Sort函数的典型用法代码示例。如果您正苦于以下问题:C++ Sort函数的具体用法?C++ Sort怎么用?C++ Sort使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: child_walker
bool
TabNavigationWalker::FocusChild ()
{
UIElement *child;
bool child_is_control;
int current_index = -1;
// Add each branch of the visual tree to the array and then sort them
// based on the TabIndex of the first Control in each branch
VisualTreeWalker child_walker (root);
while ((child = child_walker.Step ()))
g_ptr_array_add (tab_sorted, child);
if (tab_sorted->len > 1) {
Sort (tab_sorted, types);
if (ReverseTab ()) {
GPtrArray *reverse = g_ptr_array_sized_new (tab_sorted->len);
for (int i = tab_sorted->len - 1; i >= 0; i--)
g_ptr_array_add (reverse, tab_sorted->pdata [i]);
g_ptr_array_free (tab_sorted, true);
tab_sorted = reverse;
}
}
// Find the index of the currently selected node so we know which node to
// tab to next
for (uint i = 0; i < tab_sorted->len; i++)
if (tab_sorted->pdata [i] == current)
current_index = i;
// If a child of the root element is Focused and we're forward-tabbing, it means we should
// skip the entire subtree and go to the next 'root'. If we're reverse-tabbing it means we
// should Focus the root.
if (current_index != -1 && GetActiveNavigationMode (root, types) == KeyboardNavigationModeOnce) {
// If we're tabbing backwards and a child of this control is currently Focused, we
// should focus this control.
if (ReverseTab () && types->IsSubclassOf (root->GetObjectType (), Type::CONTROL))
return TabTo ((Control *)root);
return false;
}
if (tab_sorted->len > 0) {
// If the currently selected element was found at index 'i' we need to tab
// to the *next* index. If the currently selected item was not here, we
// need to start at index 0.
for (unsigned int i = 0; i < tab_sorted->len; i++) {
// If we are not cycling, it means we've tabbed to the last element of this node and so should
if ((i + current_index + 1) == tab_sorted->len && GetActiveNavigationMode (root, types) != KeyboardNavigationModeCycle)
break;
child = (UIElement *) tab_sorted->pdata [(i + current_index + 1) % tab_sorted->len];
child_is_control = types->IsSubclassOf (child->GetObjectType (), Type::CONTROL);
if (child_is_control && !((Control *)child)->GetIsEnabled ())
continue;
// When tabbing backwards, we recurse all children *before* attempting to select this node
if (ReverseTab () && WalkChildren (child))
return true;
if (child_is_control && TabTo ((Control *)child))
return true;
if (ForwardTab () && WalkChildren (child))
return true;
}
}
// If we're tabbing backwards and a child of this control is currently Focused, we
// should focus this control.
if (current_index != -1 && ReverseTab ()) {
if (types->IsSubclassOf (root->GetObjectType (), Type::CONTROL))
return TabTo ((Control *)root);
}
// Nothing could be tabbed to on this visual level
return false;
}
示例2: arrayToString
}
array<String^>^ Manager::runSort(int setSizeModifier) {
array<int>^ originalSet = af->MakeArray(setSizeModifier);
String^ orginalSetStr = arrayToString(originalSet);
array<int>^ sortedSet = sortMethod(originalSet);
String^ sortedSetStr = arrayToString(sortedSet);
array<String^>^ result = { orginalSetStr, sortedSetStr };
return result;
}
void Manager::RunTests(String^ fileName) {
Statistics^ stats = gcnew Statistics();
Sort^ sorter = gcnew Sort(stats);
stats->OpenFile(fileName);
stats->WriteToFile("Bubble Sort");
SortMethod^ bubble = gcnew SortMethod(sorter, &Sort::Bubble);
RunTest(bubble, stats);
stats->WriteToFile("Insertion Sort");
SortMethod^ insert = gcnew SortMethod(sorter, &Sort::Insertion);
RunTest(insert, stats);
stats->WriteToFile("Merge Sort");
SortMethod^ merge = gcnew SortMethod(sorter, &Sort::Merge);
RunTest(merge, stats);
stats->WriteToFile("Selection Sort");
示例3: Sort
void Material::SortTechniques()
{
Sort(techniques_.Begin(), techniques_.End(), CompareTechniqueEntries);
}
示例4: Sort
Rlist *RealSortRListNames(Rlist *list)
{
return Sort(list, &RlistItemRealLess, &RlistGetNext, &RlistPutNext, NULL);
}
示例5: int
Rlist *SortRlist(Rlist *list, int (*CompareItems) ())
{
return Sort(list, &RlistCustomItemLess, &RlistGetNext, &RlistPutNext, CompareItems);
}
示例6: ClearSaveData
int KTgaManager::FormateSaveData()
{
int nResult = false;
int nRetCode = false;
KTgaBlock *pBlock = NULL;
KTGABLOCKSAVEDATA SaveData;
int nCurrentSaveIndex = 0;
int nSaveTgaWidth = 0;
int nSaveTgaHeight = 0;
RECT rcSaveBuffer;
ClearSaveData();
Sort(SORT_TO_SAVE);
GetSaveArea(rcSaveBuffer);
nSaveTgaWidth = rcSaveBuffer.right;
nSaveTgaHeight = rcSaveBuffer.bottom;
KSaveManager::GetSelf().GetCorrectWidthAndHeight(nSaveTgaWidth, nSaveTgaHeight);
m_SaveTga.Create(nSaveTgaWidth, nSaveTgaHeight);
for (KTgaBlockArray::iterator it = m_aTgaBlock.begin(); it != m_aTgaBlock.end(); ++it)
{
pBlock = (*it);
ASSERT(pBlock);
if (!(pBlock->IsIndexChangeable()))
{
int nIndex = pBlock->GetOriginalIndex();
ASSERT(nIndex >= nCurrentSaveIndex);
for (; nCurrentSaveIndex < nIndex; ++nCurrentSaveIndex)
{
SaveData.szName[0] = _T('\0');
SaveData.nLeft = 0;
SaveData.nTop = 0;
SaveData.nWidth = 0;
SaveData.nHeight = 0;
m_aSaveData.push_back(SaveData);
}
if (pBlock->IsPosHasBeenSeted())
{
pBlock->GetName(SaveData.szName, sizeof(SaveData.szName) / sizeof(TCHAR));
SaveData.nLeft = pBlock->GetLeft() - rcSaveBuffer.left;
ASSERT(SaveData.nLeft >= 0);
SaveData.nTop = pBlock->GetTop() - rcSaveBuffer.top;
ASSERT(SaveData.nTop >= 0);
SaveData.nWidth = pBlock->GetWidth();
SaveData.nHeight = pBlock->GetHeight();
m_aSaveData.push_back(SaveData);
nRetCode = AppendSaveTgaData(pBlock, SaveData.nLeft, SaveData.nTop);
KG_PROCESS_ERROR(nRetCode);
}
else
{
SaveData.szName[0] = _T('\0');
SaveData.nLeft = 0;
SaveData.nTop = 0;
SaveData.nWidth = 0;
SaveData.nHeight = 0;
m_aSaveData.push_back(SaveData);
}
++nCurrentSaveIndex;
continue;
}
if (pBlock->IsPosHasBeenSeted())
{
pBlock->GetName(SaveData.szName, sizeof(SaveData.szName) / sizeof(TCHAR));
SaveData.nLeft = pBlock->GetLeft() - rcSaveBuffer.left;
ASSERT(SaveData.nLeft >= 0);
SaveData.nTop = pBlock->GetTop() - rcSaveBuffer.top;
ASSERT(SaveData.nTop >= 0);
SaveData.nWidth = pBlock->GetWidth();
SaveData.nHeight = pBlock->GetHeight();
m_aSaveData.push_back(SaveData);
nRetCode = AppendSaveTgaData(pBlock, SaveData.nLeft, SaveData.nTop);
KG_PROCESS_ERROR(nRetCode);
++nCurrentSaveIndex;
}
}
m_nSaveWidth = rcSaveBuffer.right;
m_nSaveHeight = rcSaveBuffer.bottom;
nResult = true;
Exit0:
return true;
}
示例7: Sort
int KTgaManager::AutoMakeupNothingDanger()
{
int nResult = false;
KTgaBlock *pBlockSelf = NULL;
KTgaBlock *pBlockPosed = NULL;
RECT rcSelf;
RECT rcPosed;
int nSelfWidth = 0;
int nSelfHeight = 0;
int nCount = (int)m_aTgaBlock.size();
int nDesiredWidth = KShow::GetSelf().GetDesiredWidth();
int nDesiredHeight = KShow::GetSelf().GetDesiredHeight();
Sort(SORT_TO_AUTO_MAKE_SIZE);
for (int nIndex = 0; nIndex < nCount; ++nIndex)
{
pBlockSelf = m_aTgaBlock[nIndex];
ASSERT(pBlockSelf);
nSelfWidth = pBlockSelf->GetWidth();
nSelfHeight = pBlockSelf->GetHeight();
if (pBlockSelf->IsPosHasBeenSeted())
continue;
pBlockSelf->SetLeft(0);
for (int i = 0; i <= nDesiredHeight - nSelfHeight; ++i)
{
i = g_GetCorrectPosition(i);
pBlockSelf->SetTop(i);
//pBlockSelf->GetByRect(rcSelf);
for (int nIndexSeted = 0; nIndexSeted < nCount; ++nIndexSeted)
{
pBlockPosed = m_aTgaBlock[nIndexSeted];
ASSERT(pBlockPosed);
if (!pBlockPosed->IsPosHasBeenSeted())
{
pBlockSelf->SetPosHasBeenSeted();
break;
}
pBlockSelf->GetByRect(rcSelf);
pBlockPosed->GetByRect(rcPosed);
if (!g_IntersectRect(rcSelf, rcPosed))
continue;
if (rcPosed.right + FRAME_DISTANCE * 2 + nSelfWidth > nDesiredWidth)
{
pBlockSelf->SetLeft(0);
break;
}
pBlockSelf->SetLeft(g_GetCorrectPosition(rcPosed.right + FRAME_DISTANCE * 2));
nIndexSeted = -1;
}
if (pBlockSelf->IsPosHasBeenSeted())
break;
}
KG_PROCESS_ERROR(pBlockSelf->IsPosHasBeenSeted());
}
nResult = true;
Exit0:
return nResult;
}
示例8: rowChanged
//--------------------------------------------------------------------------------------
//! Update the list of devices when a device changes
//--------------------------------------------------------------------------------------
void tNDP2kDevicePage::OnDeviceChanged(const tN2kName &N2kName)
{
tNDP2kDevice *pDevice;
if(tGlobal<tNDP2k>::Instance()->DeviceManager().NameToDevice(N2kName, &pDevice))
{
if(pDevice->IsAlive())
{
if (m_DeviceList.contains(pDevice))
{
// Search for device in table
for (int row=0; row < m_pTableWidget->rowCount(); ++row)
{
if (m_pTableWidget->item(row, m_NameColumn)->text() == pDevice->HexName())
{
rowChanged(row, pDevice);
if (m_SortOption >= 0)
{
if ( m_pTableWidget->IsScrolling() == false )
{
Sort();
}
}
break;
}
}
}
else
{
// Add the device if missing from the list
m_DeviceList.prepend(pDevice);
// Insert device at the beginning of the table (they are sorted anyhow)
insertDevice(pDevice, 0);
if( pDevice->ProductCode() == N2K_PRESSURE_ID )
{
tPressureSensorProxy proxy( pDevice->N2kName() );
proxy.RequestPressureConfiguration( );
}
if ( m_pTableWidget->IsScrolling() == false )
{
Sort(); //always update the selection, even if the sortOption is < 0
}
}
}
else // Device IsALive == false
{
if (m_DeviceList.contains(pDevice)) // Device Lost
{
// Search for device in table
for (int row=0; row < m_pTableWidget->rowCount(); ++row)
{
if (m_pTableWidget->item(row, m_NameColumn)->text() == pDevice->HexName())
{
m_pTableWidget->removeRow(row);
m_DeviceList.removeOne(pDevice);
break;
}
}
}
}
}
}
示例9: LoadAndSortFiles
/**
* @brief Load arrays with all directories & files in specified dir
*/
void LoadAndSortFiles(LPCTSTR sDir, DirItemArray * dirs, DirItemArray * files, bool casesensitive)
{
LoadFiles(sDir, dirs, files);
Sort(dirs, casesensitive);
Sort(files, casesensitive);
}
示例10: Sort
void Playlist::OnSortDuration() {
Sort(2);
}
示例11: ScoreEntry
void ScoreFile::Insert(const string& name, int score)
{
scores[9] = ScoreEntry(name.c_str(), score);
Sort();
needsWrite = true;
}
示例12: rate
//.........这里部分代码省略.........
/* Reset estimation history (init with zeros) since the sample
rate offset was changed */
veciSRTiCorrHist.Init(iLenCorrectionHist, 0);
iIntegTiCorrections = 0;
}
else
{
/* Tracking phase */
/* Get actual sample rate offset in Hertz */
/* const CReal rSamOffset = GetSamOffHz(iCurRes - veciSRTiCorrHist[0],
iLenCorrectionHist - 1); */
const CFReal rSamOffset = FXP (GetSamOffHz(iCurRes - veciSRTiCorrHist[0],
iLenCorrectionHist - 1));
#ifndef USE_SAMOFFS_TRACK_FRE_PIL
/* Apply result from sample rate offset estimation */
//Parameter.rResampleOffset -= CONTR_SAMP_OFF_INT_FTI * rSamOffset;
FXP (Parameter.rResampleOffset) -= CONTR_SAMP_OFF_INT_FTI * rSamOffset;
#endif
}
}
/* Delay spread length estimation --------------------------------------- */
/* Estimate the noise energy using the minimum statistic. We assume that
the noise variance is equal on all samples of the impulse response.
Therefore we subtract the variance on each sample. The total estimated
signal energy is the total energy minus the noise energy */
/* Calculate total energy */
const CFReal rTotEgy = Sum(vecrAvPoDeSpRot);
/* Sort the values of the PDS to get the smallest values */
CRealVector rSortAvPoDeSpRot(Sort(vecrAvPoDeSpRot));
/* Average the result of smallest values and overestimate result */
const long long rSigmaNoise_fxp =
(long long)(Sum(rSortAvPoDeSpRot(1, NUM_SAM_IR_FOR_MIN_STAT - 1)) /
NUM_SAM_IR_FOR_MIN_STAT * OVER_EST_FACT_MIN_STAT*(1<<FXP_TIME_SYNC_TRACK_SCALE));
/* Calculate signal energy by subtracting the noise energy from total
energy (energy cannot by negative -> bound at zero) */
const long long rSigEnergyBound_fxp =
(long long)((double)Max(rTotEgy - ((double)rSigmaNoise_fxp/(1<<FXP_TIME_SYNC_TRACK_SCALE)) * iNumIntpFreqPil,
(FXP)0)*(1<<FXP_TIME_SYNC_TRACK_SCALE));
/* From left to the right -> search for end of PDS */
rEstPDSEnd_fxp = (FXP) (iNumIntpFreqPil - 1);
rCurEnergy_fxp = 0;
bPDSResultFound = FALSE;
for (i = 0; i < iNumIntpFreqPil; i++)
{
if (bPDSResultFound == FALSE)
{
if (rCurEnergy_fxp > rSigEnergyBound_fxp)
{
/* Delay index */
rEstPDSEnd_fxp = (CReal) i;
bPDSResultFound = TRUE;
}
/* Accumulate signal energy, subtract noise on each sample */
rCurEnergy_fxp += (long long)(vecrAvPoDeSpRot[i]*(1<<FXP_TIME_SYNC_TRACK_SCALE)) - rSigmaNoise_fxp; //slu2 change
}
}
示例13: new
int ARRAY::Convert(PGLOBAL g, int k, PVAL vp)
{
int i, prec = 0;
bool b = FALSE;
PMBV ovblk = Valblk;
PVBLK ovblp = Vblp;
Type = k; // k is the new type
Valblk = new(g) MBVALS;
switch (Type) {
case TYPE_DOUBLE:
prec = 2;
case TYPE_SHORT:
case TYPE_INT:
case TYPE_DATE:
Len = 1;
break;
default:
sprintf(g->Message, MSG(BAD_CONV_TYPE), Type);
return TYPE_ERROR;
} // endswitch k
Size = Nval;
Nval = 0;
Vblp = Valblk->Allocate(g, Type, Len, prec, Size);
if (!Valblk->GetMemp())
// The error message was built by PlgDBalloc
return TYPE_ERROR;
else
Value = AllocateValue(g, Type, Len, prec);
/*********************************************************************/
/* Converting STRING to DATE can be done according to date format. */
/*********************************************************************/
if (Type == TYPE_DATE && ovblp->GetType() == TYPE_STRING && vp)
if (((DTVAL*)Value)->SetFormat(g, vp))
return TYPE_ERROR;
else
b = TRUE; // Sort the new array on date internal values
/*********************************************************************/
/* Do the actual conversion. */
/*********************************************************************/
for (i = 0; i < Size; i++) {
Value->SetValue_pvblk(ovblp, i);
if (AddValue(g, Value))
return TYPE_ERROR;
} // endfor i
/*********************************************************************/
/* For sorted arrays, get the initial find values. */
/*********************************************************************/
if (b)
Sort(g);
ovblk->Free();
return Type;
} // end of Convert
示例14: IsLight
void CLightManager::AddGeometryLights (void)
{
int nFace, nSegment, nSide, nTexture, nLight;
CSegFace* faceP;
tFaceColor* colorP;
#if 0
for (nTexture = 0; nTexture < 910; nTexture++)
nLight = IsLight (nTexture);
#endif
gameStates.render.bHaveDynLights = 1;
#if 0
if (gameStates.app.bD1Mission)
gameData.render.fAttScale [0] *= 2;
#endif
ogl.m_states.fLightRange = fLightRanges [IsMultiGame ? 1 : extraGameInfo [IsMultiGame].nLightRange];
m_headlights.Init ();
if (gameStates.render.nLightingMethod)
gameData.render.color.vertices.Clear ();
m_data.Init ();
for (nFace = gameData.segs.nFaces, faceP = FACES.faces.Buffer (); nFace; nFace--, faceP++) {
nSegment = faceP->nSegment;
if (SEGMENTS [nSegment].m_nType == SEGMENT_IS_SKYBOX)
continue;
#if DBG
if (nSegment == nDbgSeg)
nDbgSeg = nDbgSeg;
#endif
nSide = faceP->nSide;
#if DBG
if ((nSegment == nDbgSeg) && ((nDbgSide < 0) || (nSide == nDbgSide)))
nDbgSeg = nDbgSeg;
#endif
nTexture = faceP->nBaseTex;
if ((nTexture < 0) || (nTexture >= MAX_WALL_TEXTURES))
continue;
colorP = gameData.render.color.textures + nTexture;
if ((nLight = IsLight (nTexture)))
Add (faceP, &colorP->color, nLight, (short) nSegment, (short) nSide, -1, nTexture, NULL, 1);
faceP->nOvlTex = SEGMENTS [faceP->nSegment].Side (faceP->nSide)->m_nOvlTex;
nTexture = faceP->nOvlTex;
#if 0//DBG
if (gameStates.app.bD1Mission && (nTexture == 289)) //empty, light
continue;
#endif
if ((nTexture > 0) && (nTexture < MAX_WALL_TEXTURES) && (nLight = IsLight (nTexture)) /*gameData.pig.tex.info.fBrightness [nTexture]*/) {
colorP = gameData.render.color.textures + nTexture;
Add (faceP, &colorP->color, nLight, (short) nSegment, (short) nSide, -1, nTexture, NULL);
}
//if (m_data.nLights [0])
// return;
if (!gameStates.render.bHaveDynLights) {
Reset ();
return;
}
}
Sort ();
#if 0
PrintLog ("light sources:\n");
CDynLight* pl = m_data.lights [0];
for (int i = m_data.nLights [0]; i; i--, pl++)
PrintLog ("%d,%d,%d,%d\n", pl->info.nSegment, pl->info.nSide, pl->info.nObject, pl->info.bVariable);
PrintLog ("\n");
#endif
}
示例15: Sort
void nsCStringArray::Sort(void)
{
Sort(CompareCString, nsnull);
}