[STL] Vector ์ ๋ ฌ..
๋ฐ์ดํฐ๋ฅผ ์ ๋ ฌํ๋ค ๋ณด๋..
Map ์ Value Sort๊ฐ ํ์ํ๊ฒ ๋์๋ค.
๊ธฐ์ตํ๊ธฐ๋ก Map์ Key์ ๋ ฌ์ด๋ผ ๋ค๋ฅธ ์ปจํ
์ด๋๊ฐ ํ์ํ๋ค๋๊ฑธ ๊ธฐ์ตํ์ง๋ง..
ํน์๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์์๊น, ํ์
์ ์๋ ๋
์ํํ
๋ ๋ฌผ์ด๋ณด๊ณ ๊ตฌ๊ธ๋ง๋ ํด๋ณด์์ง๋ง
์ญ์๋~! ๊ธฐ์กด ๋ฐฉ๋ฒ์ผ๋ก ๊ฐ์ผํ๋ค -ใ
-
์ผ๋จ ์์ Vector ๋ณ์๋ฅผ ์ ์ธํ๊ณ ;;
vector<Temp> CityIDVector; // ์ ๋ ฌ์ ์ํ ์์ ๋ฒกํฐ
์ ๋ ฌ์ ์ํด ์์ ํด๋์ค๋ฅผ ์์ฑ.
typedef class _Temp{
public:
int CityID;
int Demand;
public:
int getInt( void){
return Demand; // ์์ ์ธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ
}
void putInt( int a, int b){
CityID = a;
Demand = b;
}
}Temp;
๋ค์๊ณผ ๊ฐ์ ํจ์๋ฅผ ๋ง๋ค์ด ๋ ์์๋ฅผ ๋น๊ตํ๋ค.
bool CompareTemp(Temp first, Temp second)
{
return first.getInt() > second.getInt();
}
๊ทธ ๋ค์์ Map์ Value ๊ฐ์ ๋ผ์ด ๋์ ๋ค์๊ณผ ๊ฐ์ด Vector์ ๋ฃ์ด ์ฃผ์๋ค.
Temp Col;
Col.putInt((*it).second->st_iCityID,(*it).second->st_iPistolDemand);
CityIDVector.push_back( Col );
๋ง์ง๋ง์ผ๋ก Sort๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ํํ๋ฉด ๋~
// ์์ ์์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌํ๋ค.
std::sort(CityIDVector.begin(),CityIDVector.end(),CompareTemp);