//The problem is: There are 10,000 employees in the company to work, the company in order to count the age distribution of workers,//Please sort out the age of these 10,000 people and analyze a better algorithm.#include <iostream>#include <vector>#include <stdlib.h>#include <string.h>#include <stdio.h>#define _MAX_AGE_#define _MIN_AGE_ 0#define _EXIT_ cout<< "There is no old age! "; exit ( -1)using namespace STD;voidGrial ( vector<int>AR) {int Array[_max_age_];//Declare an array with a space size of _max_age_. memset(Array,' + ',sizeof(Array));intn = ar.size (); for(intI=0; i<n;i++) {if(Ar[i]>=_max_age_ | | ar[i]<=_min_age_) {_exit_;}Else{Array[ar[i]]++; } }//array[n] Array subscript means the age of 1-100, and the number of people at that age is stored under each age. }intMain () { vector<int>Arr for(intI=0;i< -; i++) {Arr.push_back (rand ()% -); } grial (arr);return 0;}#include <iostream>using namespace STD;//Find the smallest number after the ordered array is rotated. intGrial (intA[],intN) {inti =0;intj = N1; while((i+1) {!=j) {intMid = (i+j)/2;if(a[0]<A[J])returna[0];//1 2 3 4 5 6 7 Consideration of the situation. if(A[i]==a[j] && a[mid]==a[i])//1 1 1 1 1 0 0 1 Consideration of the situation.{ for(; i<=j;i++) {if(A[i]>a[j])returnA[J]; }if(I>J)returnA[i]; }if(a[0]>a[mid])//Then it is compared with the first element, there are 2 cases.{j=mid; }if(a[0]<=a[mid]) {i = mid; } }returna[i]>a[j]?a[j]:a[i]; }intMain () {inta[]={1,2,3,4,5};cout<<grial (A,5) <<endl;return 0; }
C + + the smallest number after an ordered array rotation