473,508 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seeking algorithm: find last greater than

I have a sorted vector of structs, each containing a upper limit of a
range:

struct Datum
{
double upper_limit;
// other stuff
};

std::vector<Datumdata;

Given an input value, I want to find the structure that goes with this
value.

Is there a simple STL idiom to search the vector for the matching
structure?

I'm thinking I need to iterate from rbegin() to rend() until I find (p->
upper_limit input) and then return --(p->base()).
Jul 14 '08 #1
1 1527
Kenneth Porter wrote:
I have a sorted vector of structs, each containing a upper limit of a
range:

struct Datum
{
double upper_limit;
// other stuff
};

std::vector<Datumdata;

Given an input value, I want to find the structure that goes with this
value.

Is there a simple STL idiom to search the vector for the matching
structure?

I'm thinking I need to iterate from rbegin() to rend() until I find (p->
upper_limit input) and then return --(p->base()).
Sounds like you might want to use std::lower_bound or std::upper_bound.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jul 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8863
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
3
12960
by: jose luis fernandez diaz | last post by:
Hi, Does any know a algorithm to strip heading and leading blank in a string ? Tnansk, Jose Luis
28
3126
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
8
1747
by: jason | last post by:
Hello everyone, I am looking for an algorithm that would take an incremental value and map that to a case-inspecific alphanumeric string. However, I don't want the string to simply step through...
6
25348
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
0
13277
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
4
32047
prometheuzz
by: prometheuzz | last post by:
Hello (Java) enthusiasts, In this article I’d like to tell you a little bit about graphs and how you can search a graph using the BFS (breadth first search) algorithm. I’ll address, and...
6
17818
by: kamsmartx | last post by:
I'm new to programming and need some help figuring out an algorithm. I need to design some kind of algorithm which will help us define capacity for one of our portfolios....here's the problem...
6
12127
Kelicula
by: Kelicula | last post by:
Why?: One commonly used algorithm is the binary search. If you don't already know it, you should read on. Very helpful. Saves much CPU. Reduces computations exponentially. When searching...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.