本文整理汇总了C++中std::list::sort方法的典型用法代码示例。如果您正苦于以下问题:C++ list::sort方法的具体用法?C++ list::sort怎么用?C++ list::sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::list
的用法示例。
在下文中一共展示了list::sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fetch
void mlTowersInfo::fetch( std::list<std::string> & towers )const
{
for( auto iter : m_towersInfo )
{
if( iter.first.empty() == false )
towers.push_back( iter.first );
}
towers.sort(
[this]( const std::string & l, const std::string & r )
{
auto a = m_towersInfo.find( l );
auto b = m_towersInfo.find( r );
if( a == m_towersInfo.end() || b == m_towersInfo.end() )
return false;
return a->second.order < b->second.order;
} );
}
示例2: getGlobalNameForWho
bool Variables::getGlobalNameForWho(std::list<std::wstring>& lstVarName, int* iVarLenMax, bool bSorted) const
{
for (auto it : vars)
{
if (it.second->empty() == false && it.second->isGlobal())
{
std::wstring wstrVarName(it.first.getName().c_str());
lstVarName.push_back(wstrVarName);
*iVarLenMax = std::max(*iVarLenMax, (int)wstrVarName.size());
}
}
if (bSorted)
{
lstVarName.sort();
}
return true;
}
示例3: cmp
/** Collects the renderlist for the world-mesh */
void D3D11GraphicsEngineTest::GetWorldMeshRenderList(std::list<std::pair<MeshKey, MeshInfo *>>& list)
{
D3DXMATRIX view;
Engine::GAPI->GetViewMatrix(&view);
Engine::GAPI->SetViewTransform(view); // Make sure frustum-culling is working
// Querry the visible sections from GAPI
std::list<WorldMeshSectionInfo*> renderList;
Engine::GAPI->CollectVisibleSections(renderList);
// Collect meshes from sections
for(std::list<WorldMeshSectionInfo*>::iterator it = renderList.begin(); it != renderList.end(); it++)
{
for(std::map<MeshKey, WorldMeshInfo*>::iterator itm = (*it)->WorldMeshes.begin(); itm != (*it)->WorldMeshes.end();itm++)
{
if(!(*itm).first.Texture)
continue;
if(!(*itm).first.Texture->GetSurface() || !(*itm).first.Texture->GetSurface()->GetEngineTexture())
{
(*itm).first.Texture->CacheIn(0.6f);
continue;
}
list.push_back((*itm));
}
}
struct cmpstruct
{
static bool cmp(const std::pair<MeshKey, MeshInfo *>& a, const std::pair<MeshKey, MeshInfo *>& b)
{
if(a.first.Texture->HasAlphaChannel())
return false; // Render alpha last
return a.first.Texture < b.first.Texture;
}
};
// Sort by texture
list.sort(cmpstruct::cmp);
}
示例4: GetDirectoryContents
/* Not dirs, not . or .. */
static void GetDirectoryContents(const char *name, std::list<std::string> &files)
{
DIR *dir = opendir(name);
if (!dir) {
//if (-1 == mkdir(name, 0770)
Gui::Screen::ShowBadError(stringf(128, Lang::COULD_NOT_OPEN_FILENAME, name).c_str());
return;
}
struct dirent *entry;
while ((entry = readdir(dir))) {
if (strcmp(entry->d_name, ".")==0) continue;
if (strcmp(entry->d_name, "..")==0) continue;
files.push_back(entry->d_name);
}
closedir(dir);
files.sort();
}
示例5: listAllInterfaces
void devEthernet::listAllInterfaces(std::list<std::string>& ifaceNames) {
ifaceNames.clear();
ACE_Dirent dir;
if ( dir.open(topNetDir.c_str()) ) {
throw nd_error("Could not open directory " + topNetDir + " for reading.");
}
struct stat docStat;
ACE_DIRENT* entry;
while ( (entry = dir.read()) != NULL ) {
std::string entryName(entry->d_name);
if ( entryName[0] != '.' && ! isProtected(entryName) ) { ifaceNames.push_back(entryName); }
}
dir.close();
ifaceNames.sort();
}
示例6: TestForExistingItem
static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
{
static std::list<BOARD_ITEM*> itemsList;
if( aItem == NULL ) // Build list
{
// Count items to store in itemsList:
BOARD_ITEM* item;
itemsList.clear();
// Store items in list:
// Append tracks:
for( item = aPcb->m_Track; item != NULL; item = item->Next() )
itemsList.push_back( item );
// Append modules:
for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
itemsList.push_back( item );
// Append drawings
for( auto ditem : aPcb->Drawings() )
itemsList.push_back( ditem );
// Append zones outlines
for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
itemsList.push_back( aPcb->GetArea( ii ) );
NETINFO_LIST& netInfo = aPcb->GetNetInfo();
for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
itemsList.push_back( *i );
// Sort list
itemsList.sort();
return false;
}
// search in list:
return std::binary_search( itemsList.begin(), itemsList.end(), aItem );
}
示例7: FilterTargets
void FilterTargets(std::list<WorldObject*>& targets)
{
targets.sort(Trinity::ObjectDistanceOrderPred(GetCaster()));
if (targets.empty())
return;
std::list<WorldObject*> ranged, melee;
std::list<WorldObject*>::iterator itr = targets.begin();
if ((*itr)->ToCreature())
return;
while (itr != targets.end() && (*itr)->GetDistance(GetCaster()) < 5.0f)
{
melee.push_back((*itr)->ToUnit());
++itr;
}
while (itr != targets.end())
{
ranged.push_back((*itr)->ToUnit());
++itr;
}
uint32 minTargets = GetCaster()->GetMap()->Is25ManRaid() ? 8 : 3;
while (ranged.size() < minTargets)
{
if (melee.empty())
break;
WorldObject* target = Trinity::Containers::SelectRandomContainerElement(melee);
ranged.push_back(target);
melee.remove(target);
}
if (!ranged.empty())
Trinity::Containers::RandomResizeList(ranged, GetCaster()->GetMap()->Is25ManRaid() ? 3 : 1);
targets.swap(ranged);
}
示例8: grahamScan
//Realiza el algoritmo de Graham de las 3 monedas para hallar el Convex Hull S de una lista de Puntos Q.
//Devuelve una Pila con el resultado clockwise.
void grahamScan(std::list<Point2D> & Q, std::stack<Point2D> & S){
minimal = encontrarMinimal(Q); //Encuentra el minimal izquierda abajo
// std::cout<<"Minimal: "; minimal.print();
borrarMinimal(Q, minimal); //Borra el minimal de la cola
Q.sort(comparePoint2DPolar); //Ordena en forma polar
std::cout<<"Lista ordenada\n"; printList(Q);
eliminarColineales(Q); //Hace limpieza de los puntos colineales, dejando el mas lejano
std::cout<<"Lista ordenada\n"; printList(Q);
//Ubica las 3 primeras monedas
S.push(minimal); //Agrega el primero que es el minimal
//Agrega la segunda y tercera
std::list<Point2D>::iterator it = Q.begin(); //Iterador para recorrer la Q
for(unsigned int i = 0; i < 2 and it != Q.end(); i++, it++){
S.push(*it);
}
//tamanio de Q
unsigned int n = Q.size();
//Loop de Graham Scan
for(unsigned int i = 2; i < n and it != Q.end(); i++, it++){
Point2D ntt = nextToTop(S);
Point2D nt = top(S);
Point2D p = *it;
while(!leftTurn(ntt, nt, p) and (S.size() > 1)){ //Si no froman un giro a la izquierda y queda mas de un elemento en S
// printStack(S);
S.pop(); //Saco el tope de S
ntt = nextToTop(S); //Renuevo los valores y vuelvo a probar
nt = top(S);
}
S.push(p); //Agrego el elemento a S
}
}
示例9: CleanupMatches
void BadWords::CleanupMatches(std::list<Match>& matches) {
// Clean up the match list. First, remove smaller matches that are
// inside larger matches.
// Sort so that earlier and longer matches are first
matches.sort(CompareMatches);
// Remove matches that overlap with other matches. This is easy since
// the matches have been sorted.
std::list<Match>::iterator it_i = matches.begin();
while (it_i != matches.end()) {
std::list<Match>::iterator it_j = boost::next(it_i);
while (it_j != matches.end()) {
if ((*it_i).end >= (*it_j).start) {
it_j = matches.erase(it_j);
continue;
}
it_j++;
}
it_i++;
}
}
示例10: getVarsNameForWho
bool Variables::getVarsNameForWho(std::list<std::wstring>& lstVarName, int* iVarLenMax, bool bSorted) const
{
for (auto it : vars)
{
std::wstring wstrVarName(it.first.getName().c_str());
if (it.second->empty() == false)
{
types::InternalType* pIT = it.second->top()->m_pIT;
if (pIT && pIT->isFunction() == false)
{
lstVarName.push_back(wstrVarName);
*iVarLenMax = std::max(*iVarLenMax, (int)wstrVarName.size());
}
}
}
if (bSorted)
{
lstVarName.sort();
}
return true;
}
示例11: GetSortedAttributes
void nuiObject::GetSortedAttributes(std::list<nuiAttribBase>& rListToFill) const
{
CheckValid();
rListToFill.clear();
// Add classes attributes
int32 c = mClassNameIndex;
while (c >= 0)
{
std::map<nglString,nuiAttributeBase*>::const_iterator it = mClassAttributes[c].begin();
std::map<nglString,nuiAttributeBase*>::const_iterator end = mClassAttributes[c].end();
while (it != end)
{
nuiAttributeBase* pBase = it->second;
rListToFill.push_back(nuiAttribBase(const_cast<nuiObject*>(this), pBase));
++it;
}
c = mInheritanceMap[c];
}
// Add instance attributes
{
std::map<nglString,nuiAttributeBase*>::const_iterator it = mInstanceAttributes.begin();
std::map<nglString,nuiAttributeBase*>::const_iterator end = mInstanceAttributes.end();
while (it != end)
{
nuiAttributeBase* pBase = it->second;
rListToFill.push_back(nuiAttribBase(const_cast<nuiObject*>(this), pBase));
++it;
}
}
rListToFill.sort(NUIATTRIBUTES_COMPARE);
}
示例12: WndProc
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
TCHAR cap[16]=TEXT("");
static HWND hCalcButton=0;
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam==VK_RETURN){
hCalc=FindWindow(TEXT("CalcFrame"),TEXT(" алькул¤тор"));
//hCalcButton=FindWindowEx(hCalc,hCalcButton,TEXT("Button"),TEXT(""));
//SetClassLong(hCalcButton,GCL_STYLE,CS_
if (button_list.empty()){
EnumChildWindows((HWND)hCalc, EnumChildProc, (LPARAM)hWnd);
button_list.sort();
}
//ShowWindow(button_list.back(), SW_HIDE);
SetTimer(hWnd,1,1000,NULL);
}
if (wParam==VK_ESCAPE) KillTimer(hWnd,1);
break;
case WM_TIMER:
delkey(hCalc);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
示例13: matching_traveled_edges
void matching_traveled_edges(std::unordered_set<HGVertex*> &mv, GraphListEntry &g,
std::unordered_set<HGEdge*> &edge_set, std::list<TravelerList*> &traveler_lists)
{ // return a set of edges for the traveled graph format,
// optionally restricted by region or system or placeradius
std::unordered_set<TravelerList*> trav_set;
for (HGVertex *v : mv)
{ if (v->visibility < 1) continue;
for (HGEdge *e : v->incident_t_edges)
if (!g.placeradius || g.placeradius->contains_edge(e))
{ bool rg_in_rg = 0;
if (g.regions) for (Region *r : *g.regions)
if (r == e->segment->route->region)
{ rg_in_rg = 1;
break;
}
if (!g.regions || rg_in_rg)
{ bool system_match = !g.systems;
if (!system_match)
for (std::pair<std::string, HighwaySystem*> &rs : e->route_names_and_systems)
{ bool sys_in_sys = 0;
if (g.systems) for (HighwaySystem *s : *g.systems)
if (s == rs.second)
{ sys_in_sys = 1;
break;
}
if (sys_in_sys) system_match = 1;
}
if (system_match)
{ edge_set.insert(e);
for (TravelerList *t : e->segment->clinched_by) trav_set.insert(t);
}
}
}
}
traveler_lists.assign(trav_set.begin(), trav_set.end());
traveler_lists.sort(sort_travelers_by_name);
}
示例14: sortJobsByProg
void sortJobsByProg(){
// std::sort(jobs.begin(), jobs.end(), sortByProgress);
remainningJobs.sort(sortByProgress);
}
示例15: run
inline static void run(std::list<T> &c, std::size_t) {
c.sort();
}