• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ sort函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: sort

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


示例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,代码来源:scene.cpp


示例3: sort

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


示例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,代码来源:sdffsequenceelements.cpp


示例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,代码来源:anagram.cpp


示例6: sort

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


示例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,代码来源:mergeBed.cpp


示例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,代码来源:lab1pr11.cpp


示例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,代码来源:race.cpp


示例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 flags

inputs: 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 void
newGame(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,代码来源:ag.c


示例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; // Ū¤F´X­Ó¦r¤¸
				for(i=0; i<n; i++){
						double x,y;
						finput >> x >> y;
						Point a = Point(x,y);
						point.push_back(a);
				}
				struct timeval tv, tv2;
				unsigned long long int start_utime, end_utime;
				if(option == 1){
						gettimeofday(&tv, NULL);
						h.FindConvexHull_bf(point, result);
						gettimeofday(&tv2, NULL);
						start_utime = tv.tv_sec*1000000 + tv.tv_usec;
						end_utime = tv2.tv_sec*1000000 + tv2.tv_usec;
				}
				else if(option == 2){
						gettimeofday(&tv, NULL);
						h.FindConvexHull_jm(point, result);
						gettimeofday(&tv2, NULL);
						start_utime = tv.tv_sec*1000000 + tv.tv_usec;
						end_utime = tv2.tv_sec*1000000 + tv2.tv_usec;
				}
				else
						break;
				cout << "cost time: " << end_utime - start_utime << " us" <<endl;
				internal = h.FindInternalPoint(point,result);
				
				ofstream foutput("Output.txt");
				foutput << internal.size() << endl;
				
				vector<Point> upper;
				vector<Point> lower;
				upper.clear();
				lower.clear();
				for(i=0; i<internal.size(); i++){
						if(internal[i].y >= 0)
								upper.push_back(internal[i]);
						else
								lower.push_back(internal[i]);
				}
				sort(upper.begin(), upper.end(), up_compare);
				sort(lower.begin(), lower.end(), low_compare);
		
				for(i=0; i<upper.size(); i++)
						foutput << upper[i].x << " " << upper[i].y << endl;
				for(i=0; i<lower.size(); i++)
						foutput << lower[i].x << " " << lower[i].y << endl;
				foutput << endl;

				foutput << result.size() << endl;

				Point start_p = FindStartPoint(result);
				upper.clear();
				lower.clear();
				for(i=0; i<result.size(); i++){
						if(result[i] == start_p)
								continue;
						if(result[i].y > start_p.y)
								upper.push_back(result[i]);
						else
								lower.push_back(result[i]);
				}
				sort(upper.begin(), upper.end(), up_compare);
				sort(lower.begin(), lower.end(), low_compare);
				foutput << start_p.x << " " << start_p.y << endl;
				for(i=0; i<upper.size(); i++)
						foutput << upper[i].x << " " << upper[i].y << endl;
				for(i=0; i<lower.size(); i++)
						foutput << lower[i].x << " " << lower[i].y << endl;
		}

		return 0;
}
开发者ID:AwenHuang,项目名称:OOP,代码行数:91,代码来源:main.cpp


示例12: sort

void SortFilterModel::setSortOrder(const Qt::SortOrder order)
{
    sort(0, order);
}
开发者ID:KDE,项目名称:plasma-framework,代码行数:4,代码来源:datamodel.cpp


示例13: main

void main()
{
	link_list mylist;

	init_list(&mylist);

	int select = 1;
	elem_type item;
	node *p = NULL;
	while(select)
	{
		printf("*************************************************\n");
		printf("*  [1] push_back	 [2] push_front 	*\n");
		printf("*  [3] show_list	 [4] pop_back    	*\n");
		printf("*  [5] pop_front	 [6] insert_val 	*\n");
		printf("*  [7] find 	 	 [8] get_length 	*\n");
		printf("*  [9] delete_val	 [10] sort   	 	*\n");
		printf("*  [11] resever		 [12] clear 	 	*\n");
		printf("*  [13*] destroy	 [0] quit_system 	*\n");
		printf("*  [14] prior_node 	 [15] next_node 	*\n");
		printf("*************************************************\n");

		printf("请选择操作选项:> ");
		scanf("%d", &select);

		if(select == 0)
			break;

		switch(select)
		{
			case 1:
				printf("请输入要插入的数据(-1结束):>");
				while(scanf("%d", &item), item != -1)
				{
					push_back(&mylist, item);
				}
				break;
			case 2:
				printf("请输入要插入的数据(头插法, -1结束);>");
				while(scanf("%d", &item), item != -1)
				{
					push_front(&mylist, item);
				}
				break;
			case 3:
				show_list(&mylist);
				break;
			case 4:
				pop_back(&mylist);
				break;
			case 5:
				pop_front(&mylist);
				break;
			case 6:
				printf("请输入要插入的数据:>");
				scanf("%d", &item);
				insert_val(&mylist, item);
				break;
			case 7:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = find(&mylist, item);
				if (p == NULL)
				{
					printf("要查找的数据在单链表中不存在.");
				}
				else
				 	printf("在单链表查找到数据: %d\n", p->data);
				break;
			case 8:
				printf("单链表的长度为: %d\n", get_length(&mylist));
				break;
			case 9:
				printf("请输入要删除的值:> ");
				scanf("%d", &item);
				delete_val(&mylist, item);
				break;
			case 10:
				sort(&mylist);
				break;
			case 11:
				resver(&mylist);
				break;
			case 12:
				clear(&mylist);
				break;
			case 14:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = prior_node(&mylist, item);
				if (p == NULL || p == (&mylist)->head)
				{
					printf("要查找的数据在单链表中不存在前驱.\n");
				}
				else
				{
			 	 	printf("要查找的数据在单链表中的前驱为:%d.\n", p->data);	
				}
				break;
 	 	 	case 15:
//.........这里部分代码省略.........
开发者ID:qomolangmaice,项目名称:data.structures.algorithms,代码行数:101,代码来源:main.c


示例14: printf

void ME_Regression_DataSet::report_feature_statistics(int f_idx, const char *name) const
{
    vector<double> vals0,vals1;
    double avg_nz0=0, avg_nz1=0;
    double wnz0=0, wnz1=0, wz0=0, wz1=0;
    int i;

    for (i=0; i<samples.size(); i++)
    {
        double val = 0;
        int j;
        for (j=0; j<samples[i].f_vals.size(); j++)
        {
            if (samples[i].f_vals[j].f_idx == f_idx)
            {
                val = samples[i].f_vals[j].val;
                break;
            }
        }

        double weight = samples[i].weight;
        int label = samples[i].label;

        if (val != 0)
        {
            if (label == 0)
            {
                wnz0+= weight;
                avg_nz0 += weight * val;
                vals0.push_back(val);
            }
            else
            {
                wnz1+= weight;
                avg_nz1 += weight * val;
                vals1.push_back(val);
            }
        }
        else
        {
            if (label == 0)
            {
                wz0+=weight;
            }
            else
                wz1+=weight;
        }
    }

    if (avg_nz0 != 0)
        avg_nz0/=wnz0;
    if (avg_nz1 != 0)
        avg_nz1/=wnz1;

    printf("Statistics for feature %d ",f_idx);
    if (name)
        printf(" %s",name);
    printf("\n");
    printf("Class 0:\n");
    printf("weight samples with non-zero vals: %.3f (%.2f)  samples with zero val: %.3f (%.2f)\n",
           wnz0,wnz0/(wnz0+wz0),wz0,wz0/(wnz0+wz0));

    printf("Avg weighted: %g    non-weighted vals:\n",avg_nz0);
    sort(vals0.begin(),vals0.end());

    // prints avgs of tenths of the values
    int ts=vals0.size()/10;
    int p=0;
    for (i=0; i<9; i++)
    {
        int next=p+ts;
        int j;
        double av=0;
        for (j=p; j<next; j++)
            av+=vals0[j];

        printf("%.4f  ",av/ts);
        p+=ts;
    }

    double av=0;
    for (i=p; i<vals0.size(); i++)
        av+=vals0[i];

    printf("%.4f\n",av/(vals0.size()-p));


    printf("Class 1:\n");
    printf("weight samples with non-zero vals: %.3f (%.2f)  samples with zero val: %.3f (%.2f)\n",
           wnz1,wnz1/(wnz1+wz1),wz1,wz1/(wnz1+wz1));

    printf("Avg weighted: %g    non-weighted vals:\n",avg_nz1);
    sort(vals1.begin(),vals1.end());

    // prints avgs of tenths of the values
    ts=vals1.size()/10;
    p=0;
    for (i=0; i<9; i++)
    {
        int next=p+ts;
//.........这里部分代码省略.........
开发者ID:kennyhelsens,项目名称:jwrapper-pepnovo,代码行数:101,代码来源:ME_Regression_DataSet.cpp


示例15: sort

void CZapitBouquet::sortBouquetByNumber(void)
{
	sort(tvChannels.begin(), tvChannels.end(), CmpChannelByChNum());
	sort(radioChannels.begin(), radioChannels.end(), CmpChannelByChNum());
}
开发者ID:FFTEAM,项目名称:neutrino-mp-cst-next,代码行数:5,代码来源:bouquets.cpp


示例16: QSortFilterProxyModel

FilteredPlacesModel::FilteredPlacesModel(QObject *parent) : QSortFilterProxyModel(parent)
, m_placesModel(new KFilePlacesModel(this))
{
    setSourceModel(m_placesModel);
    sort(0);
}
开发者ID:cmacq2,项目名称:plasma-desktop,代码行数:6,代码来源:computermodel.cpp


示例17: wiggleSort

 void wiggleSort(vector<int>& nums) {
     int mid = (nums.size() - 1) / 2;
     sort(nums.begin(), nums.end());  // O(nlogn) time
     reversedTriPartitionWithVI(nums, nums[mid]);  // O(n) time, O(1) space
 }
开发者ID:1461190388,项目名称:LeetCode,代码行数:5,代码来源:wiggle-sort-ii.cpp


示例18: QTreeWidget

LibraryTreeWidget::LibraryTreeWidget(QWidget *parent)
	: QTreeWidget(parent)
{
	setSelectionMode(QAbstractItemView::ExtendedSelection);
	setDragEnabled(true);
	viewport()->setAcceptDrops(true);
	setDropIndicatorShown(true);
	setDragDropMode(QAbstractItemView::InternalMove);

	invisibleRootItem()->setFlags(invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled);

	setHeaderHidden(true);

	setEditTriggers(QAbstractItemView::EditKeyPressed | QAbstractItemView::SelectedClicked);

	addNewFileAction_ = new QAction(tr("Add New File..."), this);
	connect(addNewFileAction_, SIGNAL(triggered()), this, SLOT(addNewFile()));

	importToLibraryAction_ = new QAction(tr("Add Existing Files..."), this);
	connect(importToLibraryAction_, SIGNAL(triggered()), this, SLOT(importToLibrary()));

//	newFontAction_ = new QAction(tr("New Font..."), this);
//	connect(newFontAction_, SIGNAL(triggered()), this, SLOT(newFont()));

	newFolderAction_ = new QAction(tr("New Folder"), this);
	connect(newFolderAction_, SIGNAL(triggered()), this, SLOT(newFolder()));

	removeAction_ = new QAction(tr("Remove"), this);
	connect(removeAction_, SIGNAL(triggered()), this, SLOT(remove()));

	renameAction_ = new QAction(tr("Rename"), this);
	//renameAction_->setShortcut(Qt::Key_F2);
	connect(renameAction_, SIGNAL(triggered()), this, SLOT(rename()));

	sortAction_ = new QAction(tr("Sort"), this);
	connect(sortAction_, SIGNAL(triggered()), this, SLOT(sort()));

	codeDependenciesAction_ = new QAction(tr("Code Dependencies..."), this);
	connect(codeDependenciesAction_, SIGNAL(triggered()), this, SLOT(codeDependencies()));

	insertIntoDocumentAction_ = new QAction(tr("Insert Into Document"), this);
	connect(insertIntoDocumentAction_, SIGNAL(triggered()), this, SLOT(insertIntoDocument()));

	projectPropertiesAction_ = new QAction(tr("Properties..."), this);
	connect(projectPropertiesAction_, SIGNAL(triggered()), this, SLOT(projectProperties()));

	automaticDownsizingAction_ = new QAction(tr("Automatic Downsizing"), this);
	automaticDownsizingAction_->setCheckable(true);
	connect(automaticDownsizingAction_, SIGNAL(triggered(bool)), this, SLOT(automaticDownsizing(bool)));

    excludeFromExecutionAction_ = new QAction(tr("Exclude from Execution"), this);
    excludeFromExecutionAction_->setCheckable(true);
    connect(excludeFromExecutionAction_, SIGNAL(triggered(bool)), this, SLOT(excludeFromExecution(bool)));

    setContextMenuPolicy(Qt::CustomContextMenu);
	connect(this, SIGNAL(customContextMenuRequested  (const QPoint&)),
			this, SLOT  (onCustomContextMenuRequested(const QPoint&)));

	connect(this, SIGNAL(itemDoubleClicked  (QTreeWidgetItem*, int)),
			this, SLOT  (onItemDoubleClicked(QTreeWidgetItem*, int)));

	connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
			this, SLOT  (onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));

	isModifed_ = false;
	xmlString_ = toXml().toString();

	QTimer* timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(checkModification()));
	timer->start(500);
}
开发者ID:dev-life,项目名称:gideros,代码行数:71,代码来源:librarytreewidget.cpp


示例19: main

//main function
int main() {
	//print out some application instructions
	printf("Enter some numbers that are bigger than 0 and smaller than %u\n", UINT_MAX);
	printf("If you enter the number 0 the applications will print out all given numbers as a sorted list\n\n---- Input --------------\n\n");
	
	
	//declare a c-generic datatype
	List container;
	
	//initialize the list
	memset(&container, 0, sizeof(List));
	construct(List, &container, sizeof(unsigned int), FREEOBJ);
	
	
	
	while(1) {
		//read out an element
		unsigned int* t=malloc(sizeof(unsigned int));
		scanf("%u", t);
		
		//add it to the list
		push_back(List, &container, t, DYNAMIC);
		
		//break if zero is the input
		if(*t==0)
			break;
	}
	
	
	printf("\n\n---- Unsorted --------------\n\n");
	
	//set print functions
	set_print(List, &container, print);
	
	//print all element in our list
	print_all(List, &container);
	
	
	//lets have fun with iterators (instead using print_all)
	printf("\n\n---- Iterators --------------\n\n");
	
	ListIter* i = create(ListIter, &container);
	//check if it is empty - this will never happen
	if(!empty(List, &container)) {
		//place the iterator at the first element
		head(ListIter, i);
		
		do {
			printf("%u\n", *((unsigned int*)retrieve(ListIter, i)));
			
		}while(!next(ListIter, i));
	}
	
	//give the memory free
	destroy(ListIter, i);
	
	
	printf("\n\n---- Sorted ASC --------------\n\n");
	
	//set the sort functions
	set_compare(List, &container, intcmp);
	
	//use the in-place sort
	sort(List, &container);
	
	
	print_all(List, &container);
	
	
	//give the memory free
	destruct(List, &container);
	
	printf("\n\n");
	return 0;
}
开发者ID:matthieuriolo,项目名称:c-generic-library,代码行数:76,代码来源:tutorial.c


示例20: atoi

//-------------------------------------------------------------------------
// func: Bouquet Edit
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_set_bouquet_edit_form(CyhookHandler *hh, std::string para)
{
	if (!(hh->ParamList["selected"].empty()))
	{
		int selected = atoi(hh->ParamList["selected"].c_str()) - 1;
		int mode = NeutrinoAPI->Zapit->getMode();
		ZapitChannelList* channels = mode == CZapitClient::MODE_TV ? &(g_bouquetManager->Bouquets[selected]->tvChannels) : &(g_bouquetManager->Bouquets[selected]->radioChannels);
		for(int j = 0; j < (int) channels->size(); j++) {
			hh->ParamList["bouquet_channels"] +=
				string_printf("<option value=\""
					PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS
					"\">%s</option>\n",
					(*channels)[j]->channel_id,
					(*channels)[j]->getName().c_str());
		}
		ZapitChannelList Channels;
		Cha 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sortAllChildren函数代码示例发布时间:2022-05-30
下一篇:
C++ sopen函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap