// list をソートする関数 #include #include using namespace std; typedef struct { int key; char s[8]; } LANK; LANK tbl[6]= { {5,"suzuki"}, {3,"tanaka"}, {1,"aoki"}, {4,"maeda"}, {6,"yamada"}, {2,"ozawa"} }; void Sort(list &pv) { list::iterator p,q,ep; int sw; for(p=pv.begin(); p!=pv.end(); p++) cout << p->key << p->s << endl; ep= pv.end(); ep--; sw= 1; while(sw) { for(sw=0,p=pv.begin(); p!=ep; p++) { q= p; q++; if (p->key > q->key) { sw =1; swap(*p,*q); } } } } void main() { list v; list::iterator p; int i; for(i=0; i<6; i++) v.push_back(tbl[i]); Sort(v); for(p=v.begin(); p!=v.end(); p++) cout << p->key << " " << p->s << endl; }