当前位置: 首页>>代码示例>>C++>>正文


C++ MyList::sort方法代码示例

本文整理汇总了C++中MyList::sort方法的典型用法代码示例。如果您正苦于以下问题:C++ MyList::sort方法的具体用法?C++ MyList::sort怎么用?C++ MyList::sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyList的用法示例。


在下文中一共展示了MyList::sort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test

void test()
{
	MyList<Hero> myList;
	ifstream file("heros.txt");
	copy(istream_iterator<Hero>(file), istream_iterator<Hero>(), back_inserter(myList));
	myList.sort([](const Hero &a, const Hero &b) {
		return a.power > b.power;
	});
	cout << "Sorted by power:" << endl;
	for (auto i: myList)
		cout << i << endl;
	myList.sort([](const Hero &a, const Hero &b) {
		int scorea = a.strength + a.intelligence + a.power + a.charisma + a.luck;
		int scoreb = b.strength + b.intelligence + b.power + b.charisma + b.luck;
		return scorea > scoreb;
	});
	cout << "Sorted by total score:" << endl;
	for (auto i: myList)
		cout << i << endl;
}
开发者ID:lv-zheng,项目名称:MemoryLeakDetection,代码行数:20,代码来源:main.cpp

示例2: node

/*
 * The method takes a string of characters and for each character calculates the char frequency.
 * Than creates a list of nodes for binary tree
 *
 * @param charStr The character string
 * @return The list of nodes sorted by char frequency
*/
MyList<Node> createListNode(string *charStr){
    MyUnordered_map<char, int> symbols;
    for (size_t i = 0; i < charStr->size(); i++){
        symbols[charStr->at(i)] = 0;
    }

    for (size_t i = 0; i < charStr->size(); i++){
        symbols[charStr->at(i)]++;
    }

    MyList<Node> listNode;
    for (auto it = symbols.begin(); it != symbols.end(); ++it){
        Node node(it -> value, it -> key);
        listNode.push_back(node);
    }
    listNode.sort();
    return listNode;
}
开发者ID:aokhotnikov,项目名称:cs-b,代码行数:25,代码来源:zip.cpp

示例3: main

int main()
{
	MyList list;
	list.push_back(3);
	list.push_back(2);
	list.push_back(10);
	list.push_back(5);
	list.push_back(4);

	cout << "Note: The program did not specify means of input. As such, the program makes a list of 5 integers"
		 << " as seen above this line in the code and sorts them.\n" << endl;
	cout << "Before sort: " << list.toString();
	
	cout << endl;

	list.sort();

	cout << "After Sort: "<< list.toString() << endl; 
 	
  	return 0;
} 
开发者ID:austinhofmann,项目名称:School,代码行数:21,代码来源:main.cpp

示例4: main


//.........这里部分代码省略.........

	for (it.toFirst();it.current();++it) { //Parkplaetze bewerten
  	n = nl_i->find(it.currentKey());
		if ((n->classname()).compare("agriculture") == 0){
			QString *val = new QString("0.0");
			unsigned int size=((*n)["size"])->toUInt();
			if(size>4700){
			  n->replace("p", val);
			}
		}
	}

	nl_i->calcNewGEOValues(gN,gS,gW,gE,newX,newY,xRes,yRes);
	MyList hl;
	it.toFirst();
	while(it.current()) {
		float p;
//<<<<<<< ga_bu_industrie.cpp
// 	  if (!(*it)["p"]) p=0.5;
// 	  else p=(*it)["p"]->toFloat();
//		if(p>0.0000001) {
//		  Help* h = new Help(p,it.currentKey());
//		  hl.append(h);
//		}
//=======
 	  if (!(**it)["p"]) p=(float)0.987;
 	  else p=(**it)["p"]->toFloat();
		Help* h = new Help(p,it.currentKey());
		hl.append(h);
//>>>>>>> 1.6
		++it;
	}
	
	hl.sort();
	newX = int((gE-gW) / xRes);//calculate new image size
	newY = int((gN-gS) / yRes);//calculate new image size
	qDebug("$$$newX: %d, newY: %d, xRes: %f, yRes: %f, gN: %f, gS: %f, gE: %f, gW: %f",
	  newX, newY, xRes, yRes, gN, gS, gE, gW);
	
	QFile fp(argv[2]); // 'XML' - description
  if (!fp.open(IO_WriteOnly)) qDebug("write: file not accesable to %s\n",argv[2]);
  QTextStream str(&fp);
	
	QDict<int> dict( 17, FALSE ); //dictionary for the class nr.
	QArray<NodeInfo*> infolist(nl_i->size()+1); // array of pointers to NodeInfo
	Help *pl;
	int i = 1;
	int helplabel = 0;//, label = 0;
	Image out_img(typeid(signed int),newX,newY,1); //generate out image
#ifdef WIN32
	QArray <int> vec(nl_i->size()+1); 
#else
	int vec[nl_i->size()+1]; 
#endif
	for (int ix=0; ix<nl_i->size()+1; ix++) vec[ix]=0; //info for labeling
	out_img.setGeoCoordinates(gW,gN,gE,gS);
  for ( pl=hl.first(); pl != 0; pl=hl.next() ) {
		Node *node=nl_i->find(pl->cl_name());
		//label = node->id();
		NodeInfo* ni = new NodeInfo(newX, newY);
		ni->id(i);
		ni->cl_name(node->classname());
		ni->name(node->name());
		//cout << "##### " << i <<": "<< node->name() << " - " << node->classname()<<endl;//<<"; p:"<< (node->getValue("p"))->toFloat()<<endl;
	  ni->p((node->getValue("p"))->toFloat());
//	    qDebug("$$§§§§ node->p: %f",node->getValue("p"))->toFloat());
开发者ID:BackupTheBerlios,项目名称:geoaida-svn,代码行数:67,代码来源:ga_bu_industrie.cpp


注:本文中的MyList::sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。