|
[code]void SortTypeName(std::vector<CString>& vecName)
{
std::map<CString,std::vector<CString>> mapName; //mapName<ZC-1,vector<ZC-1-1>>
for (size_t i = 0;i < vecName.size(); i++)
{
CString &strName = vecName[i];
int n = 0;
for (int i = strName.GetLength();i > 0; i--)
{
char p = strName[i];
if (p == _T('-'))
{
n = i;
break;
}
}
CString strLeft = strName.Left(n);
auto it = mapName.find(strLeft);
if (it == mapName.end())
{
std::vector<CString> vecName;
vecName.push_back(strName);
mapName.insert(std::make_pair(strLeft,vecName));
}
else
{
it->second.push_back(strName);
}
}
//对vector<ZC-1-1>进行排序
vecName.clear();
for (auto it = mapName.begin();it != mapName.end();++it)
{
std::vector<std::pair<int,CString>> vecPair;
for (size_t i = 0;i < it->second.size();i++)
{
CString strName = it->second[i];
int n = 0;
for (int i = strName.GetLength();i > 0; i--)
{
char p = strName[i];
if (p == '-')
{
n = i;
break;
}
}
CString strRight = strName.Mid(n + 1);
int nRight = _ttoi(strRight);
std::pair<int,CString> pairName(nRight,strName);
vecPair.push_back(pairName);
}
//排序
for (size_t nIndex1 = 0;nIndex1 < vecPair.size(); nIndex1++)
{
for (size_t nIndex2 = 0 ; nIndex2 < vecPair.size() - nIndex1 - 1; nIndex2++)
{
if (vecPair[nIndex2].first > vecPair[nIndex2+1].first)
{
std::swap(vecPair[nIndex2],vecPair[nIndex2+1]);
}
}
}
for (size_t i = 0;i < vecPair.size();i++)
{
vecName.push_back(vecPair[i].second);
}
}
}[/code] |
|