| | |
Find highest value in List
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
I am using a List where I wonder how it is possible to find the MaxValue searching trough
Value1[0] until Value1[3].
In this case it should return: 12
I have found a ::Max function but this will only consider the 2 values inside the paranthes wich then will return: 100.
For the std:: you can use std::max_element( , ) for this purpose to search through a range of elements.
Value1[0] until Value1[3].
In this case it should return: 12
I have found a ::Max function but this will only consider the 2 values inside the paranthes wich then will return: 100.
For the std:: you can use std::max_element( , ) for this purpose to search through a range of elements.
C++ Syntax (Toggle Plain Text)
List<double>^ Value1= gcnew List<double>(); Value1->Add(12); Value1->Add(2); Value1->Add(7); Value1->Add(4); double MaxValue1 = 0; MaxValue1 = System::Math::Max( 0, 100 );
Last edited by Jennifer84; Oct 1st, 2008 at 11:02 am.
Well You can use the sort function to list and get the max value .
For that you will need to write a bool comp() function for your datatype.
Comparison function that, taking two values of the same type than those contained in the list object, returns true if the first argument goes before the second argument in the specific order (i.e., if the first is less than the second), and false otherwise.
After sorting. The item in your list will be the greatest i guess.
For that you will need to write a bool comp() function for your datatype.
Comparison function that, taking two values of the same type than those contained in the list object, returns true if the first argument goes before the second argument in the specific order (i.e., if the first is less than the second), and false otherwise.
After sorting. The item in your list will be the greatest i guess.
Last edited by Sky Diploma; Oct 1st, 2008 at 11:07 am.
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
I understand. I have a wondering here. If you would use a for loop to iterate through a series of elements to replace a greater value to find the greatest value.
Will this be as fast as the sortingmethod or perheps this is difficult to say ?
Why I wonder is because I am not 100 % sure how to write that comparison before I begin.
Will this be as fast as the sortingmethod or perheps this is difficult to say ?
Why I wonder is because I am not 100 % sure how to write that comparison before I begin.
Last edited by Jennifer84; Oct 1st, 2008 at 11:14 am.
Well I dint see it before. But seems that you have a list of doubles in the list.
So you can just use
And then print out the last item in the list.
So you can just use
C++ Syntax (Toggle Plain Text)
Value1.sort();
And then print out the last item in the list.
•
•
•
•
Originally Posted by Sky Diploma
Well You can use the sort function to list and get the max value .
For that you will need to write a bool comp() function for your datatype.
Comparison function that, taking two values of the same type than those contained in the list object, returns true if the first argument goes before the second argument in the specific order (i.e., if the first is less than the second), and false otherwise.
After sorting. The item in your list will be the greatest i guess.
C++ Syntax (Toggle Plain Text)
double max = Value1[0]; for each ( double value in Value1 ) { if ( value > max ) max = value; }
I'd be surprised if the sorting method was faster.
New members chased away this month: 4
•
•
•
•
Erm, what's wrong with a simple loop?
>Will this be as fast as the sortingmethod or perheps this is difficult to say ?C++ Syntax (Toggle Plain Text)
double max = Value1[0]; for each ( double value in Value1 ) { if ( value > max ) max = value; }
I'd be surprised if the sorting method was faster.
Well I dint see that . The List was containing Double's I thought that it is some datatype . I stand corrected though. I guess i already have replied too.
![]() |
Similar Threads
- Sorting A Linked List--- Please help (C++)
- c++ functions for grades (C++)
- Please help me find what small errors i have!! (C++)
- No Colors Anymore? (DaniWeb Community Feedback)
- Random number with ascending order help (C++)
- How can I get Highest, Lowest and Average ? (C++)
- A little help please (C)
- finding the highest value help (C)
Other Threads in the C++ Forum
- Previous Thread: .rfind for Managed
- Next Thread: How to store a genogram in C++
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






