Find out the index of a vector which has the min element

P

Plissken.s

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.
 
D

Daniel T.

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();
 
V

Victor Bazarov

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
 
A

Alf P. Steinbach

* (e-mail address removed):
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

Alf P. Steinbach

* Alf P. Steinbach:
* (e-mail address removed):

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.
 
D

Daniel T.

"Alf P. Steinbach said:
* Alf P. Steinbach:

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.
 
D

Dietmar Kuehl

Alf said:
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...
 
A

Alf P. Steinbach

* Dietmar Kuehl:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top