本文整理汇总了C++中EList::sort方法的典型用法代码示例。如果您正苦于以下问题:C++ EList::sort方法的具体用法?C++ EList::sort怎么用?C++ EList::sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EList
的用法示例。
在下文中一共展示了EList::sort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TSP
std::pair<std::vector<NodeID>, EdgeWeight> TSP(Graph* G){
NodeID* n = new NodeID[G->size()];
NodeID* mi = new NodeID[G->size()];
EdgeWeight total = 0;
EdgeWeight min = -1;
for(int i = 0; i < G->size(); i++){
n[i] = i;
};
/*NodeID** nn = new NodeID*[G->size()];
for(int i = 0; i < G->size(); i++){
nn[i] = new NodeID[G->size()];
};*/
EList l;
NWPair p;
bool found;
for(int i = 0; i < G->size(); i++){
total = 0;
for(int i = 0; i < G->size(); i++){
n[i] = -1;
};
n[0] = i;
l = G->getAdj(i);
l.sort(sortWeight);
p = l.front();
total = total + p.second;
n[1] = p.first;
for(int j = 0; j < G->size() - 2; j++){
l = G->getAdj(p.first);
l.sort(sortWeight);
p = l.front();
found = true;
while(found){
found = false;
for(int q = 0; q < G->size(); q++){
if(p.first == n[q]){
l.pop_front();
p = l.front();
found = true;
};
};
};
p = l.front();
total = total + p.second;
n[j+2] = p.first;
};
total = total + G->weight(n[0],n[G->size()-1]);
if(min == -1 || min > total){
min = total;
for(int i = 0; i < G->size(); i++){
mi[i] = n[i];
};
};
};
/*do {
for(int i = 0; i < (G->size() - 1); i++){
total = total + G->weight(n[i],n[i+1]);
};
total = total + G->weight(n[G->size()-1], n[0]);
if(min == -1 || min > total){
min = total;
for(int i = 0; i < G->size(); i++){
mi[i] = n[i];
};
};
total = 0;
} while ( next_permutation (n,n+G->size()) );*/
//vector<NodeID> wut (*mi, *mi + sizeof(*mi) / sizeof(int) );
//NodeID in[] = {0,3,4,1,2};
//vector<NodeID> wut2 (in, in + sizeof(in) / sizeof(int) );
vector<NodeID> wut3;
for(int i = 0; i < G->size(); i++){
wut3.push_back(mi[i]);
};
std::pair<std::vector<NodeID>, EdgeWeight> omg (wut3,min);
/*NodeID in[] = {0,1,2,3,4};
vector<NodeID> wut (in, in + sizeof(in) / sizeof(int) );
//vector<NodeID> wut = NULL;
//vector<NodeID> hu;
cout << "what" << G->size() << endl;
cout << "no where " << endl;
EdgeWeight wtf = 6.7;
std::pair<std::vector<NodeID>, EdgeWeight> omg (wut,wtf);*/
return omg;
};
示例2: sort
/**
* Sort the edits in the provided list.
*/
void Edit::sort(EList<Edit>& edits) {
edits.sort(); // simple!
}