求最大值最小值的方法 时间复杂度O(n)

#include    
#include 
#include 
#include 
using namespace std;

template  class Urand{      //生成随机数
  bitset used;
public:
	Urand(){ srand(time(0)); }
	double operator() ();
};

template
inline double Urand::operator()()
{
	if(used.count() == UpperBound)
		used.reset();
	size_t newval;
	while(used[newval = rand() % UpperBound])
		;
	used[newval] = true;
	return newval*0.1;
}

int main(int argc, char* argv[])
{
	Urand<10> u;
	double darr[10];
	double first = 0.0;
	double second = 0.0;
	double min = 0.0;
	double max = 0.0;
	for ( int i = 0; i < 10; ++i)
	{
		darr[i] = u();
	}
    
	int num = sizeof(darr)/sizeof(darr[0]);
	bool flag = false;

	if( num%2==0 )
    {
        flag = true;
    }
	else
	{
        flag = false;
	}
    
	if(flag)
	{  
	   int i= 0;
	   first = darr[0];
	   second = darr[1];
	   if(firstdarr[i] ) 
				{
                    min = darr[i];
				}
				if( maxdarr[i+1] )
				{
                    min = darr[i+1];
				}
				if( max

你可能感兴趣的:(求最大值最小值的方法 时间复杂度O(n))