定位顺序表中最大和最小值
1 #include<iostream> 2 #include<cstdlib> 3 4 using namespace std; 5 6 int main(int argc, char const *argv[]) 7 { 8 int n, *data; 9 cin>>n; 10 data = (int*)malloc(n*sizeof(int)); 11 for (int i = 0; i < n; ++i) 12 { 13 cin>>data[i]; 14 } 15 int Lmax = 0,Lmin = 0; 16 for(int i=1;i<n;i++) 17 { 18 if(data[i]>data[Lmax]) 19 { 20 Lmax = i; 21 } 22 if (data[Lmin]>data[i]) 23 { 24 Lmin = i; 25 } 26 } 27 cout<<"Lmax="<<Lmax<<endl; 28 cout<<"Lmin="<<Lmin; 29 return 0; 30 }