Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 993377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:24:50+00:00 2026-05-16T06:24:50+00:00

Code: vector<weight *> &res; vector<weight>::iterator it = lower_bound(w.begin(), w.end(), queryweight); while(it != w.end()) {

  • 0

Code:

  vector<weight *> &res;
  vector<weight>::iterator it = lower_bound(w.begin(), w.end(), queryweight);
  while(it != w.end()) {
      weight *w  = &(*it);
      if(w->weight >= 60) break;
      res.push_back(w);
      it++;
  }

I think the lower_bound do a binary search (?), so in the end, does the C++ code intend to get the weights wanted? Where it starts and stops? And what does the while loop in this case do? thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:24:51+00:00Added an answer on May 16, 2026 at 6:24 am

    lower_bound returns the lowest iterator (i.e. position in the vector) of an element that is not less than the third parameter – here, queryweight. The while loop then goes through the remaining elements and, until it reaches an element that has a wight of greater than or equal to 60 adds them to the vector res. I assume the input vector w is sorted, otherwise this function wouldn’t make much sense.

    Line by line:

    // Declare a vector of pointers to 'weight' objects, called res.
    // (I assume here that the "&" in the original question was a mistake.)
    vector<weight *> res;
    
    // Find the iterator that points to the lowest element in vector 'w'
    // such that the element is >= queryweight.
    vector<weight>::iterator it = lower_bound(w.begin(), w.end(), queryweight);
    
    // From this element forwards until the end of vector 'w'
    while(it != w.end()) {
        // Get a pointer to the element.
        weight *w  = &(*it);
        // If the 'wight' property of this element is >= 60, stop.
        if(w->wight >= 60) break;
        // Push the element onto the 'res' vector.
        res.push_back(w);
        // Move to the next element.
        it++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found that this C++ code: vector<int> a; a.push_back(1); a.push_back(2); vector<int>::iterator it = a.begin();
Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please consider the following code: vector<int> myVector; myVector.push_back(10); myVector.erase(myVector.end()); This code compiles and runs
Is there any problem with my code ? std::vector<int[2]> weights; int weight[2] = {1,2};
In the following code: class SomeClass { vector<int> i; vector<bool> b; public: int& geti()
Getting vector iterator not deferencable for code below, but I don't see why. I
I have a problem with iterator. Could you explain me why this code: vector<vector<int>
Related Question: vector <unsigned char> vs string for binary data . My code uses
unsigned int j = 0; openListIterator = openListVector.begin (); while (exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].connectedExitPoint >= openListVector[j].pointId) &&
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.