473,662 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stl map - the lowest and greatest key

Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.

Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.

My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?

Simple test (using gcc) shows it is true, but I've found comments it
is not.

Thanks for advice,
Tomasz Milewski

Feb 20 '07 #1
4 2919
* tomek milewski:
Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.

Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.

My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?
Read your own second paragraph.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 20 '07 #2
On Feb 20, 11:00 am, "tomek milewski" <milewski.tom.. .@gmail.com>
wrote:
Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.

Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.

My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?
Unless you created your map with your own comparator as parameter then
std::less will be used, this means that the <-operator will be used to
compare objects. This means that the smallest (according to the
operator) element will be first and the largest last.

--
Erik Wikström

Feb 20 '07 #3
tomek milewski wrote:
Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.

Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.

My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?
Assuming the iterators are valid, yes.
Simple test (using gcc) shows it is true, but I've found comments it
is not.
What comments said otherwise?
Feb 20 '07 #4
"tomek milewski" <mi************ *@gmail.comwrot e in message
news:11******** **************@ v45g2000cwv.goo glegroups.com.. .
Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.

Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.

My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?
begin() and rbegin() are specified to give you the first and the last
element in the container. Whether these are the ones with the lowest and the
greatest value depends on your sorting predicate. The standard map uses the
less<operator and thus, all elements in the container will be sorted
ascending if you do not specify otherwise.
Simple test (using gcc) shows it is true, but I've found comments it
is not.
Are you sure that those comments did not refer to user specified sorting
like the following:

map<T, T, std::greater<T MyMap;

which would give you a map with descending order.

HTH
Chris
Feb 21 '07 #5

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

Similar topics

8
7735
by: Mike Nolan | last post by:
As far as I can tell, Postgres has no equivalent to greatest and least functions in Oracle. Yes, you can do the same thing with a case statement, but at the expense of writing MUCH longer SQL statements. Is this something that is on or can be added to the 'to do' list? I could write a series of user-defined functions to do specific comparisons (such as comparing several dates and returning the greatest one) but there doesn't appear to...
7
4172
by: Mathew Butler | last post by:
Suppose I have a table t with columns id, col1, col2, col3, col4, col5, col6 all numeric. I want to query the table and for each value of col<x> in the resultset I want to identify the largest value in each of the columns. For example, with the following dataset: id, col1, col2, col3, col4, col5, col6 1,2,3,4,5,6,7 2,8,6,5,4,3,2 3,2,3,9,4,2,1 I want a query to generate the following output: 1,7
26
2300
by: pamelafluente | last post by:
Hi , I have a DIV element in a page with a lot of other stuff (the page can scroll several times) absolutely positioned: <div id="MyDIV" <br<brFooter </div> Just after the page load, I would like to find the lowest element in the page and set the "TOP" property of the DIV some 50 pixels below of such lowest
5
5436
by: owz | last post by:
Hi again had some more problems, all help welcome. Access 2000, SQL My problem is as stated in the title. I want 2 display the highest and lowest priced car sold for this month. This is what I have. SELECT CarSales.Car_Reg,MAX (Purchased_Price) AS Highest_Sale FROM CarSales WHERE Purchased_Price=(SELECT MIN(Purchased_Price)AS Smallest_Sale FROM...
54
6608
namcintosh
by: namcintosh | last post by:
First of all, here is my program: #include <iostream> #include <conio> using namespace std; //Function prototype void getscore(int&, int&, int&, int&, int&); void findLowest (int, int, int, int, int, int); int main()
4
13686
by: sdlt85 | last post by:
Hi, Can someone help me with an idea on how to start writing a C++ code for generating greatest common divisor and the linear combination of two intergers represented as gcd(m, n)= mx + ny and adding them it will give us the greatest common divisor and I need to use the extended Euclidean algorithm. I already have the code for the greatest common divisor but I dont know how to do the linear combination. This is what I have:
3
5690
by: stressedstudent | last post by:
I dont know where I am going wrong so I dont know which part to post, this is what I have, can anyone help me figure out where I am going wrong? THanks for any and all help. // into to c++ // This program should use a loop that lets the user enter a series of integers. // The user should enter -99 to signal the end of the series. // After all the numbers have been entered, // the program should display the largest and smallest numbers...
5
6321
by: davenet | last post by:
Hi, I'm new to Python and working on a school assignment. I have setup a dictionary where the keys point to an object. Each object has two member variables. I need to find the smallest value contained in this group of objects. The objects are defined as follows:
7
7393
by: Alberto Fortuny | last post by:
Hey guys, any idea as to how to find the lowest value and the highest value in this 2D array? I made the functions to find the lowest and highest, but all im getting on execution is a 1 on both, no matter what number i input. Here's my code #include <cstdlib> #include <iostream> using namespace std; const int MONKEYS = 3; const int DAYS = 7; double average = 0;
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4180
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
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 we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.