Current location - Loan Platform Complete Network - Big data management - A java programming problem, how to find the number of repeated numbers in an array and sort them in descending order.
A java programming problem, how to find the number of repeated numbers in an array and sort them in descending order.
# include & ltiostream & gt? # include & lt string & gt? # include & ltfstream & gt? Use namespace std? int count = 0; ? void countNum(int a[],int start,int finish)? {? //cout & lt; & lt start & lt& lt" \ n "<& lt finish & lt<" \ n "; ? int middle =(start+finish)/2; ? if(start & gt; End)? Return; ? If(a[ middle ]==2)? {? count++; ? countNum(a,start,middle- 1); ? CountNum(a, middle+1, end); ? //cout & lt; & lt "come here"<& ltmiddle & lt& ltendl? } else if(a[middle]& gt; 2)? {? countNum(a,start,middle- 1); ? } Otherwise {

CountNum(a, middle+1, end);

}

//Returns the count; ? }? int main()? { int s[ 1000]; ? ifstream INF(" 1 . txt "); ? int I = 0; And (! inf.eof())

{ inf & gt& gts[I]; i++; }? //int s[]={ 1,2,2,2,3 }; ? int start = 0; //,finish = NUM- 1; ? countNum(s,start,I- 1); ? Cout & lt& lt counts & lt& ltendl} extended data.

# include & lt iterator & gt

Template & lttypenamebiIter & gt

voidinsertion_sort(biIterbegin,biIterend)

{

typedeftypenamestd::iterator _ traits & lt; Bill & gt* value type value type;

biinterbond = begin;

Std::advance (bond,1);

for(; Bond! = end; Std::advance (bond, 1)){

value _ typekey = * bond

BiIterins = bonds;

biIterpre = ins

std::advance(pre,- 1);

And (ins! = begin & amp& amp* pre> key) {

* ins = * pre

std::advance(ins,- 1);

std::advance(pre,- 1);

}

* ins = key

}

}

References:

Baidu encyclopedia sorting