// 同时需找最小最大元素.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#define N 100
using namespace std;
double a[N];
int _tmain(int argc, _TCHAR* argv[])
{
int cases;
cout<<"请输入需要排序的案例个数:"<<endl;
cin>>cases;
while(cases--)
{
memset(a,0.0,sizeof(a));
int n;
cout<<"请输入需要排序的元素的个数:"<<endl;
cin>>n;
cout<<"请输入需要排序的元素:"<<endl;
int i = 0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
double min,max;
if(n%2)
{
min=max=a[0];
i=1;
}
else
{
if(a[1]>a[0])
{
min=a[0];
max=a[1];
}
else
{
min=a[1];
max=a[0];
}
i=2;
}
for(;i<n;i+=2)
{
if(a[i+1]>a[i])
{
if(min>a[i])
min=a[i];
if(max<a[i+1])
max=a[i+1];
}
else
{
if(min>a[i+1])
min=a[i+1];
if(max<a[i])
max=a[i];
}
}
cout<<"最小元素是:"<<endl;
cout<<min<<endl;
cout<<"最大元素是:"<<endl;
cout<<max<<endl;
}
system("pause");
return 0;
}