您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sort函数代码示例

51自学网 2021-06-03 08:07:05
  C++
这篇教程C++ sort函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sort函数的典型用法代码示例。如果您正苦于以下问题:C++ sort函数的具体用法?C++ sort怎么用?C++ sort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

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

示例1: sort

void BackgroundUtil::SortBackgroundChangesArray( vector<BackgroundChange> &vBackgroundChanges ){	sort( vBackgroundChanges.begin(), vBackgroundChanges.end(), CompareBackgroundChanges );}
开发者ID:Highlogic,项目名称:stepmania-event,代码行数:4,


示例2: assert

void DecoSceneNode::RenderAllSceneObjects(DecoRenderInterface* RI, DecoCamera* camera, SceneObjectType objType, DecoDrawType drawType){	vector<DecoRenderData*> tempSortList;	vector<DecoRenderData*> translucentDrawList;	vector<DOUBLE> distanceList;	ConvexVolume viewFrustum = camera->getViewFrustum();	INT toRender = 0, beRendered = 0;	DecoRenderData* floor = NULL, *ceiling = NULL;	DecoLight* Lights[MAX_LIGHT];	INT numEffectiveLights = 0;		for (vector<DecoSceneObject*>::iterator objIter = sceneObjs.begin(); objIter != sceneObjs.end(); objIter++)	{		DecoSceneObject* obj = *objIter;		if (obj->IsRenderable() && (objType == AllT || obj->GetType() == objType))		{			DecoRenderData* objDecoRenderData = obj->GetRenderData();			assert(objDecoRenderData);			//if (viewFrustum.BoxCheck(objDecoRenderData->GetBoundingBox()) != CF_Outside)			{				if (objDecoRenderData->NeedSort())				{					DOUBLE distSqr = (camera->getEye() - objDecoRenderData->GetBoundingBox().GetCenter()).lengthSqr();					distanceList.push_back(distSqr);					sort(distanceList.begin(), distanceList.end());					vector<DOUBLE>::iterator it = find(distanceList.begin(), distanceList.end(), distSqr);					translucentDrawList.insert(translucentDrawList.begin() + (it - distanceList.begin()), objDecoRenderData);				}				else				{					GetRelevantLights(objDecoRenderData, numEffectiveLights, Lights);					objDecoRenderData->Render(RI, Lights, numEffectiveLights, drawType);					DecoStat::GetSingleton()->CumulateObjectRendered(1);				}#ifdef DEBUG_BOUNDINGBOX				RI->SetColor(0xff0000ff);				objDecoRenderData->RenderBoundingBox(RI);#endif			}			DecoStat::GetSingleton()->CumulateObjectTotal(1);		}	}	for (vector<DecoRenderData*>::iterator translucentRenderDataIter = translucentDrawList.begin(); translucentRenderDataIter != translucentDrawList.end(); translucentRenderDataIter++)	{		GetRelevantLights((*translucentRenderDataIter), numEffectiveLights, Lights);		(*translucentRenderDataIter)->RenderOpaqueSection(RI, Lights, numEffectiveLights, drawType);		DecoStat::GetSingleton()->CumulateObjectRendered(1);	}	for (vector<DecoRenderData*>::iterator translucentRenderDataIter = translucentDrawList.begin(); translucentRenderDataIter != translucentDrawList.end(); translucentRenderDataIter++)	{		GetRelevantLights((*translucentRenderDataIter), numEffectiveLights, Lights);//.........这里部分代码省略.........
开发者ID:ksaishashank,项目名称:ProjectSoft,代码行数:101,


示例3: sort

void DhQAbstractTableModel::Dvhsort(int x1) {  return sort(x1);}
开发者ID:bennofs,项目名称:hsQt,代码行数:3,


示例4: sort

void SDFFelementManager::generate(){  channelManager* cmanager=parser->get_cmanager();  sort(); // sort the elements according to time  // calculate the duration of the sequence  if (end_time<0) {    use_end_time=extract_end_time();  } else {    use_end_time=end_time;  }  // initialize the sequence Generator and add all used channels  std::map<std::string, std::vector<SDFFsequenceElement*> >::const_iterator i;  for (i=elements.begin(); i!=elements.end(); ++i) {    generator->add_used(i->first);    //std::cout<<i->first<<" added/n";  }  generator->init(cmanager, sample_timestep, use_end_time);  //std::cout<<generator->report()<<std::endl;  //std::cout<<"going through items ..."<<std::endl;  // go through all elements and call their generate() function  for (i=elements.begin(); i!=elements.end(); ++i) {    double vstart=0; // contains the value of the channel at t=0    double t0=0; // end time of last instruction    double v0=vstart; // last value of last instruction ... initial value befor first instruction    cm_channel ch=cmanager->get(i->first); // description of the current channel    //std::cout<<std::endl<<i->first<<":  /n";    if (i->second.size()>0) {      if (i->second[0]->extract_real_t_start()==0) v0=i->second[0]->get_startvalue(); // if the first element starts at t=0                                                                                    // we have to get the start value from there      for (size_t j=0; j<i->second.size(); j++) {        //std::cout<<j;        double t1=i->second[j]->extract_real_t_start(); // start time of current instruction        // if there is a gap between the last and the current instruction, we have to fill it:        if (t1>t0) {          if (ch.type==cmAnalogOutput) { // analog channel            //std::cout<<" gap_set_analog t0="<<t0<<"  t1="<<t1<<"  v0="<<v0<<"/n";            generator->set_analog(i->first, t0, t1, cmanager->scale_value(i->first, v0));          } else { // digital channel            //std::cout<<" gap_set_digital t0="<<t0<<"  t1="<<t1<<"  v0="<<v0<<"/n";            generator->set_digital(i->first, t0, t1, cmanager->invert_value(i->first, v0>0.2));          }        }        // generate the current instruction        i->second[j]->generate();        // store end time and end value of current instruction        t0=i->second[j]->extract_real_t_end();        v0=i->second[j]->get_endvalue();      }      // now we have to check whether there is a gap between the instruction and use_end_time      if (t0<use_end_time) {        if (ch.type==cmAnalogOutput) { // analog channel          //std::cout<<" endgap_set_analog t0="<<t0<<"  t1="<<use_end_time<<"  v0="<<v0<<"/n";          generator->set_analog(i->first, t0, use_end_time, cmanager->scale_value(i->first, v0));        } else { // digital channel          //std::cout<<" endgap_set_digital_end t0="<<t0<<"  t1="<<use_end_time<<"  v0="<<v0<<"/n";          generator->set_digital(i->first, t0, use_end_time, cmanager->invert_value(i->first, v0>0.2));        }      }    } else {      // here we set the channel to the standard initial value 0, stored in vstart!      if (ch.type==cmAnalogOutput) { // analog channel        generator->set_analog(i->first, 0, use_end_time, cmanager->scale_value(i->first, vstart));      } else { // digital channel        generator->set_digital(i->first, 0, use_end_time, cmanager->invert_value(i->first, vstart>0.2));      }    }  }};
开发者ID:jkriege2,项目名称:sdfflib,代码行数:74,


示例5: find_anagrams

//********************************************************************void find_anagrams(HWND hwnd){   char msgstr[81] ;   //  read data out of hwnd:IDC_PHRASE   char input_bfr[MAX_PKT_CHARS+1] ;   uint input_bfr_len = GetWindowTextA (GetDlgItem(hwnd,IDC_PHRASE) , input_bfr, MAX_PKT_CHARS);   if (input_bfr_len > MAX_PKT_CHARS)        input_bfr_len = MAX_PKT_CHARS ;   input_bfr[MAX_PKT_CHARS] = 0 ;   if (vflag)  //lint !e506 !e774      syslog("find_anagrams: [%u] [%s]/n", input_bfr_len, input_bfr) ;   //  scan for separator char   excl_idx = 0 ; //  reset exclusions list   char *hd ;   char *tl = strchr(input_bfr, '!');   if (tl != NULL) {      *tl++ = 0 ; //  NULL-term word list, point to exclusions list      while (LOOP_FOREVER) {         tl = strip_leading_spaces(tl);         if (*tl != 0) {            hd = tl ;            tl = strchr(hd, ' ');            if (tl != NULL) {               *tl++ = 0 ;               //  hd points to one exclusion arg            }            add_to_excl_list(hd);            if (tl == NULL) {               break;            }         }      }   }   status_message("Begin new anagram search") ;   // clear_message_area(&this_term);   clear_message_area();   if (excl_idx == 0) {      status_message("excl: <none>", 1);   }   else   {      uint slen = sprintf(msgstr, "excl: ");      for (uint idx=0; idx<excl_idx; idx++) {         slen += (uint) sprintf(msgstr+slen, "%s ", excl_list[idx]);      }      status_message(msgstr, 1);   }   delete_wordlist() ;   ZeroMemory((char *) &freq[0], sizeof(freq)) ;   nletters = 0 ;   for (char *p = input_bfr; *p != 0; p++) {      if (*p != ' ') {         freq[(uint) (u8) *p]++ ;         nletters++;      }   }   if (maxgen == 0)       maxgen = nletters;      wordlist = buildwordlist ();   if (wordlist == NULL) {      syslog("Empty dictionary or no suitable words./n");      return ;   }   wordlist = sort (wordlist);   initfind (wordlist);   solutions_found = 0 ;   findanags (0, forgelinks (wordlist), nletters);   if (solutions_found == 0) {      status_message("no anagrams found for input string !") ;   } else {      // reverse_list_entries() ;      // InsertListViewItems(solutions_found);  //  This triggers drawing of listview      myTerminal->reverse_list_entries() ;      update_listview();      wsprintf(msgstr, "%u anagrams found", solutions_found) ;      status_message(msgstr) ;   }}
开发者ID:DerellLicht,项目名称:winagrams,代码行数:87,


示例6: sort

void DhQAbstractProxyModel::Dvhsort(int x1) {  return sort(x1);}
开发者ID:bennofs,项目名称:hsQt,代码行数:3,


示例7: printf

void BedMerge::ReportMergedScores(const vector<string> &scores) {    if (scores.size() > 0) {        printf("/t");        // convert the scores to floats        vector<float> data;        for (size_t i = 0 ; i < scores.size() ; i++) {            data.push_back(atof(scores[i].c_str()));        }            if (_scoreOp == "sum") {            printf("%.3f", accumulate(data.begin(), data.end(), 0.0));        }        else if (_scoreOp == "min") {            printf("%.3f", *min_element( data.begin(), data.end() ));        }        else if (_scoreOp == "max") {            printf("%.3f", *max_element( data.begin(), data.end() ));        }        else if (_scoreOp == "mean") {            double total = accumulate(data.begin(), data.end(), 0.0);            double mean = total / data.size();            printf("%.3f", mean);        }        else if (_scoreOp == "median") {            double median = 0.0;            sort(data.begin(), data.end());            int totalLines = data.size();            if ((totalLines % 2) > 0) {                long mid;                mid = totalLines / 2;                median = data[mid];            }            else {                long midLow, midHigh;                midLow = (totalLines / 2) - 1;                midHigh = (totalLines / 2);                median = (data[midLow] + data[midHigh]) / 2.0;            }            printf("%.3f", median);        }        else if ((_scoreOp == "mode") || (_scoreOp == "antimode")) {             // compute the frequency of each unique value             map<string, int> freqs;             vector<string>::const_iterator dIt  = scores.begin();             vector<string>::const_iterator dEnd = scores.end();             for (; dIt != dEnd; ++dIt) {                 freqs[*dIt]++;             }             // grab the mode and the anti mode             string mode, antiMode;             int    count = 0;             int minCount = INT_MAX;             for(map<string,int>::const_iterator iter = freqs.begin(); iter != freqs.end(); ++iter) {                 if (iter->second > count) {                     mode = iter->first;                     count = iter->second;                 }                 if (iter->second < minCount) {                     antiMode = iter->first;                     minCount = iter->second;                 }             }             // report             if (_scoreOp == "mode") {                 printf("%s", mode.c_str());             }             else if (_scoreOp == "antimode") {                 printf("%s", antiMode.c_str());             }         }         else if (_scoreOp == "collapse") {                vector<string>::const_iterator scoreItr = scores.begin();            vector<string>::const_iterator scoreEnd = scores.end();            for (; scoreItr != scoreEnd; ++scoreItr) {                if (scoreItr < (scoreEnd - 1))                    cout << *scoreItr << ";";                else                    cout << *scoreItr;            }        }    }    else {                cerr << endl              << "*****" << endl              << "*****ERROR: No scores found to report for the -scores option. Exiting." << endl              << "*****" << endl;        exit(1);    }}
开发者ID:cjfields,项目名称:bedtools,代码行数:91,


示例8: main

//.........这里部分代码省略.........				large = conversion;				inputs.push_back(conversion);			}			//If input is less than largest value goes in through another comparison			else if (conversion < large)			{				//If input is greater than the smallest and smaller than the largest it is a middle value				//Outputs middle value while notifying user				if (conversion > small)				{					inputs.push_back(conversion);				}				//If input is smaller than smallest prints out the input as new smallest value and sets small value to this number				else if (conversion < small)				{					small = conversion;					inputs.push_back(conversion);				}				//If input is equal to smallest then prints out the input as smallest value and sets small value to this number				else				{					small = conversion;					inputs.push_back(conversion);				}			}			//If input is equal to largest then prints out the input as largest value and sets large value to this number			else			{				large = conversion;				inputs.push_back(conversion);			}		}		else if (unit == "ft")		{						conversion = ((input / 100) * 2.54) / 12;							//If the input is larger than the largest value prints out the input as new largest value and sets large value to this number			if (conversion > large)			{				large = conversion;				inputs.push_back(conversion);			}			//If input is less than largest value goes in through another comparison			else if (conversion < large)			{				//If input is greater than the smallest and smaller than the largest it is a middle value				//Outputs middle value while notifying user				if (conversion > small)				{					inputs.push_back(conversion);				}				//If input is smaller than smallest prints out the input as new smallest value and sets small value to this number				else if (conversion < small)				{					small = conversion;					inputs.push_back(conversion);				}				//If input is equal to smallest then prints out the input as smallest value and sets small value to this number				else				{					small = conversion;					inputs.push_back(conversion);				}			}			//If input is equal to largest then prints out the input as largest value and sets large value to this number			else			{				large = conversion;				inputs.push_back(conversion);			}		}		else 		{			cout << "Incorrect unit please enter valid unit." << endl;			break;		}	}	double sum;	for (int count = 0; count < inputs.size(); count++)		{		sum += inputs[count];	}		sort (inputs.begin(), inputs.end());		for (int element = 0; element < inputs.size(); element++)		{		cout << "The value of position " << element << " is " << inputs[element] << " meters. ";	}			cout << "/n" << "The largest value was " << large << " in meters." << endl;	cout << "The smallest value was " << small << " in meters." << endl;	cout << "The number of values entered was " << inputs.size() << "." << endl;	cout << "The sum of all the values was " << sum << " in meters." << endl;		return 0;}
开发者ID:ssharar,项目名称:CSCE-121,代码行数:101,


示例9: norm

Vector2u Race::getNearestValidSquare(unsigned PlayerNumber){    Vector2u Dim=track.getDim();    vector<double> norm(Dim.x*Dim.y,0);    Vector2d Position=Player[PlayerNumber].PositionBeforeDeath;    for (unsigned k=0; k<Dim.x*Dim.y;++k)    {        unsigned k1= k % Dim.x;        unsigned k2= k / Dim.x;        norm[k]=sqrt(pow(k1+0.5-Position.x,2)+pow(k2+0.5-Position.y,2));    }    vector<int> index(norm.size(), 0);    for (unsigned i = 0 ; i != index.size() ; i++) {        index[i] = i;    }    sort(index.begin(), index.end(),[&](const int& a, const int& b) {return (norm[a] < norm[b]);});    unsigned j=0;    bool SquareValid=false;    bool CarCollision=false;    vector<PROPERTIES> InvalidTiles={FALL,WALL};    while (SquareValid==false || CarCollision==true)    {        CarCollision=false;        SquareValid=true;        unsigned k1=index[j]%Dim.x;        unsigned k2=index[j]/Dim.x;        Tile* CurrentTile=track.getTile(k1,k2);        Detect Detection=CurrentTile->Detection;        for (unsigned i=0; i<InvalidTiles.size(); i++)        {            if (Detection.x.count(InvalidTiles[i])==1)            {                SquareValid=0;            }        }        if(CurrentTile->isSquare==0)        {            SquareValid=0;        }        Player[PlayerNumber].Position=Vector2d(k1+0.5, k2+0.5);        for (unsigned i=0; i< Player.size();++i)        {            Car *Car1,*Car2;            if(i==PlayerNumber)            {                continue;            }            Car1=&Player[PlayerNumber];            Car2=&Player[i];            vector<Vector2d> Bounding1=Car1->Bounding;            for (unsigned k=0; k<Bounding1.size();k++)            {                Bounding1[k]=RotateVector(Bounding1[k],Player[PlayerNumber].Rotation);                Bounding1[k]+=Player[PlayerNumber].Position;            }            Vector2d Center1=accumulate(Bounding1.begin(),Bounding1.end(),Vector2d(0,0))/static_cast<double>(Bounding1.size());            vector<Vector2d> Bounding2=Car2->Bounding;            for (unsigned k=0; k<Bounding2.size();k++)            {                Bounding2[k]=RotateVector(Bounding2[k],Player[i].Rotation);                Bounding2[k]+=Player[i].Position;            }            Vector2d Center2=accumulate(Bounding2.begin(),Bounding2.end(),Vector2d(0,0))/static_cast<double>(Bounding2.size());            if( InPolygon(Bounding1,Bounding2) || InPolygon(Center1,Bounding2) || InPolygon(Center2,Bounding1) )            {                CarCollision=1;            }        }        j++;        if (j==Dim.x*Dim.y)        {            cerr<<"Failed to Find Valid Square!!"<<endl;        }    }    return Vector2u(index[j-1]%Dim.x,index[j-1]/Dim.x);}
开发者ID:Jonesey13,项目名称:CatandMouse,代码行数:82,


示例10: list

/***********************************************************synopsis: do all of the initialisation for a new game:          build the screen	  get a random word and generate anagrams	  (must get less than 66 anagrams to display on screen)	  initialise all the game control flagsinputs: head - first node in the answers list (in/out)        dblHead - first node in the dictionary list	screen - the SDL_Surface to display the image	letters - first node in the letter sprites (in/out)outputs: n/a***********************************************************/static voidnewGame(struct node** head, struct dlb_node* dlbHead,         SDL_Surface* screen, struct sprite** letters){    char guess[9];    char remain[9];    int happy = 0;   /* we don't want any more than ones with 66 answers */                     /* - that's all we can show... */    int i;	/* show background */	strcpy(txt, language);	ShowBMP(strcat(txt,"images/background.bmp"),screen, 0,0);	destroyLetters(letters);    assert(*letters == NULL);	while (!happy) {        char buffer[9];        getRandomWord(buffer, sizeof(buffer));		strcpy(guess,"");		strcpy(rootWord, buffer);		bigWordLen = strlen(rootWord)-1;		strcpy(remain, rootWord);		rootWord[bigWordLen] = '/0';		/* destroy answers list */		destroyAnswers(head);		/* generate anagrams from random word */		ag(head, dlbHead, guess, remain);		answersSought = Length(*head);		happy = ((answersSought <= 77) && (answersSought >= 6));#ifdef DEBUG		if (!happy) {			Debug("Too Many Answers!  word: %s, answers: %i",                   rootWord, answersSought);		}#endif	}#ifdef DEBUG    Debug("Selected word: %s, answers: %i", rootWord, answersSought);#endif    /* now we have a good set of words - sort them alphabetically */    sort(head);	for (i = bigWordLen; i < 7; i++){		remain[i] = SPACE_CHAR;	}	remain[7] = '/0';	remain[bigWordLen]='/0';	shuffleWord(remain);	strcpy(shuffle, remain);	strcpy(answer, SPACE_FILLED_STRING);	/* build up the letter sprites */    assert(*letters == NULL && screen != NULL);	buildLetters(letters, screen);	addClock(letters, screen);	addScore(letters, screen);	/* display all answer boxes */	displayAnswerBoxes(*head, screen);	gotBigWord = 0;	score = 0;	updateTheScore = 1;	gamePaused = 0;	winGame = 0;	answersGot = 0;	gameStart = time(0);	gameTime = 0;	stopTheClock = 0;}
开发者ID:elpollodiablo1,项目名称:Anagramarama--WebOS-Tablet,代码行数:96,


示例11: main

int main(){		Convexhull h;		vector<Point> point;		vector<Point> result;		vector<Point> internal;		while(1){				int i,option,n;				cout << "Please choose method: (1)brute force (2)Jarvis's march (3)exit" <<endl;				cin >> option;								ifstream finput("Input.txt");							internal.clear();				point.clear();				result.clear();								finput >> n; // 
C++ sortAllChildren函数代码示例
C++ sopen函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。