Hi,
How can I find out the index of a vector which has the min element?
I know how to find out the * value * of a vector which has the min
element.
But how can I find out its index?
for example, [100, 98, 1, 98, 28], I would like the function to return
2.
Thank you. 7 7150
In article <11*********************@u72g2000cwu.googlegroups. com>, Pl********@gmail.com wrote: Hi, How can I find out the index of a vector which has the min element? I know how to find out the * value * of a vector which has the min element. But how can I find out its index?
for example, [100, 98, 1, 98, 28], I would like the function to return 2.
Thank you.
return min_element( vec.begin(), vec.end() ) - vec.begin();
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
* Pl********@gmail.com: How can I find out the index of a vector which has the min element?
Look in the header <algorithm> for something akin to "min element".
Hm, are you sure this isn't HOMEWORK?
I'm pretty sure it is, because of the suggestive wording. I just hope
nobody writes your code for you.
I know how to find out the * value * of a vector which has the min element.
I don't, so you're way ahead of me there. How do you define the value
of a vector, as something other than the vector, that is?
But how can I find out its index?
for example, [100, 98, 1, 98, 28], I would like the function to return 2.
--
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? Pl********@gmail.com wrote: How can I find out the index of a vector which has the min element? I know how to find out the * value * of a vector which has the min element. But how can I find out its index?
for example, [100, 98, 1, 98, 28], I would like the function to return 2.
If you can find the value, couldn't you _remember_ the index where you
found it? How _do_ you find the "value"?
V
--
Please remove capital As from my address when replying by mail
* Alf P. Steinbach: * Pl********@gmail.com: How can I find out the index of a vector which has the min element?
Look in the header <algorithm> for something akin to "min element".
Hm, are you sure this isn't HOMEWORK?
I'm pretty sure it is, because of the suggestive wording. I just hope nobody writes your code for you.
Of course somebody did...
This fact, that people do post homework here, and the fact that other
people actually do their homework, here, must be saying something.
I'm just not sure what.
--
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?
In article <46************@individual.net>,
"Alf P. Steinbach" <al***@start.no> wrote: * Alf P. Steinbach: * Pl********@gmail.com: How can I find out the index of a vector which has the min element?
Look in the header <algorithm> for something akin to "min element".
Hm, are you sure this isn't HOMEWORK?
I'm pretty sure it is, because of the suggestive wording. I just hope nobody writes your code for you.
Of course somebody did...
This fact, that people do post homework here, and the fact that other people actually do their homework, here, must be saying something.
I'm just not sure what.
I'm in a bad mood, what can I say. I've done three homework problems
already today. :-/
I can't always tell though.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Alf P. Steinbach wrote: I'm pretty sure it is, because of the suggestive wording. I just hope nobody writes your code for you.
Of course somebody did...
I enjoy writing solutions to homework assignments and I post them
if I think that the solution is kind "creative". For most of these
"solutions" it should be pretty clear that they weren't written by
the student...
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
* Dietmar Kuehl: Alf P. Steinbach wrote: I'm pretty sure it is, because of the suggestive wording. I just hope nobody writes your code for you. Of course somebody did...
I enjoy writing solutions to homework assignments and I post them if I think that the solution is kind "creative". For most of these "solutions" it should be pretty clear that they weren't written by the student...
Well, yes, that's something else entirely. The last one I saw from you
could absolutely never be mistaken for something a student produced...
;-) I enjoy them immensely (and perhaps some homework poster will
actually hand in such a solution!), keep 'em coming!
TIA.,
- Alf
--
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Noah Spitzer-Williams |
last post by:
Hello guys,
I would like to do something seemingly simple: find out if an
element in an array that is passed to my function exists.
I used to think I could just do: if (arr) ...
However, if...
|
by: Hagen |
last post by:
Hello,
in a recent thread "speed of vector vs array" I read about the problem
of the slow acces by addressing vector elements by indexing,
unfortunately I see no workaround in my case.
My...
|
by: Adam Teasdale Hartshorne |
last post by:
I would be extremely grateful if somebody could tell me what as I
getting wrong with this little bit of code to find the index of a
particular element in a std::vector
std::vector<int>...
|
by: Steve Edwards |
last post by:
Hi,
Given a map:
typedef map<long, string, greater<long> > mapOfFreq;
Is there a quicker way to find the rank (i.e. index) of the elememt that
has the long value of x?
At the moment I'm...
|
by: Draw |
last post by:
Hi All,
Just a thought, about the find() algorithm in the C++ STL. I read that
the find algorithm can take a range of iterators. If it does not find
the element it is looking for in that range...
| |
by: Henning Hasemann |
last post by:
I'm using a stl-priority queue and want
- find out if a certain item is contained in the queue
- to be able iterate over all items without having to pop() them, order
does not matter.
I couldnt...
|
by: boheman |
last post by:
Hi, I am wondering if there is a simple and quick way to return the
indices of sorted vector.
for example, I have a vector<intx containing {5, 2, 3, 0, 2}.
I can use
sort(x.begin(), x.end(),...
|
by: desktop |
last post by:
How do I find the last element in the list numsx defined below?
int* myfind(int* arr_start, int* arr_end, int& s) {
int not_found = 666;
int* result = ¬_found;
while (arr_start !=...
|
by: OriginalCopy |
last post by:
This is a demonstrative code which could be used for debugging purposes. And yet I don't know how to insert the necessary data on line 63, purely syntactically speaking ? I'm a beginner with STL, and...
|
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,...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
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 ...
| |
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...
| |