Find out the biggest number in a int list
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
int max(list<int> a_list)
{
cout << "You gave me a list with a length of " << a_list.size() << "." << endl;
a_list.sort();
a_list.reverse();
auto iterator = a_list.begin(); //create a iterator
advance(iterator, 0); //give a 0 index, get the expected value in that list
cout << *iterator << " is the biggest in this list." << endl; //from pointer address get int value
return *iterator;
}
int main ()
{
//std::list<int> mylist;
//list included in std namespace.
list<int> mylist={2, 3, 4, 1, 0}; //define a list contains int value
max(mylist); //call max function
return 0;
}
#include <list>
#include <iterator>
using namespace std;
int max(list<int> a_list)
{
cout << "You gave me a list with a length of " << a_list.size() << "." << endl;
a_list.sort();
a_list.reverse();
auto iterator = a_list.begin(); //create a iterator
advance(iterator, 0); //give a 0 index, get the expected value in that list
cout << *iterator << " is the biggest in this list." << endl; //from pointer address get int value
return *iterator;
}
int main ()
{
//std::list<int> mylist;
//list included in std namespace.
list<int> mylist={2, 3, 4, 1, 0}; //define a list contains int value
max(mylist); //call max function
return 0;
}