U E D R S I H C RSS
ID
Password
Join
빛을 느낄 수 있는건 어둠을 알기 때문이다. - 송용완

 * 짬나면 소스별로 설명을 하도록 하겠습니다. :) 갑자기 간단히 예제를 짜놓으면 좋겠다 싶어 넣어둡니다.
#pragma warning(disable : 4786)
#include <iostream>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef struct {
	int a;
	int b;
	string text;
} _TEST_TYPE;

// x와 y를 교환해야할 경우 true 반환
struct greater_TEST_TYPE {
    bool operator()(const _TEST_TYPE& x, const _TEST_TYPE& y) const {
		return x.a > y.a;
	}
};

map<int, _TEST_TYPE, greater<int> > testmap;
set<_TEST_TYPE, greater_TEST_TYPE> testset;

void printmap()
{
	for (map<int, _TEST_TYPE, greater<int> >::iterator i = testmap.begin(); i != testmap.end(); advance(i, 1))
	{
		cout << i->first << ":" << i->second.a << "," << i->second.b << "," << i->second.text << endl;
	}
}

void printset()
{
	cout << "--------------------" << endl;
	for (set<_TEST_TYPE>::iterator i2 = testset.begin(); i2 != testset.end(); advance(i2, 1))
	{
		cout << i2->a << "," << i2->b << "," << i2->text << endl;
	}
}

int main(int argc, char* argv[])
{
	for (int n = 0; n < 20; n++)
	{
		_TEST_TYPE t1;
		t1.a = n;
		t1.b = 40;
		t1.text = 50;
		testmap.insert(pair<int, _TEST_TYPE>(n, t1));
		testset.insert(t1);
	}
	printmap();
	printset();
	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-10-28 12:42:54
Processing time 0.0286 sec