# Divide and conquer recursion: Find the maximum value of the array element, the minimum value

Source: Internet
Author: User

//Divide and conquer recursion, find the maximum value of the array element, the minimum value/*** Save the resulting maximum, minimum value *@authorAdministrator **/ Public classValues {Private intMax; Private intmin;  PublicValues (intMaxintmin) {         This. max=Max;  This. min=min; }     Public intGetmax () {returnMax; }     Public voidSetmax (intmax) {         This. Max =Max; }     Public intgetmin () {returnmin; }     Public voidSetmin (intmin) {         This. Min =min; }}/*** Divide and conquer recursively find the maximum number of elements in an array, the minimum number *@authorAdministrator **/ Public classMinmax { Public voidMin_max (intA[],intSinte,values Values) {Values lValues=NewValues (0,0); Values rValues=NewValues (0,0); if(e==s+1| | e==1) {            if(a[s]>=A[e])                {Values.setmax (a[s]);            Values.setmin (A[e]); }            Else{Values.setmax (a[e]);            Values.setmin (A[s]); }            return; }                intMid= (e+s)/2; Min_max (A,mid+1, e,lvalues);        Min_max (a,s,mid,rvalues); Values.setmax (Lvalues.getmax ()>rvalues.getmax ()?Lvalues.getmax (): Rvalues.getmax ()); Values.setmin (Lvalues.getmin ()<rvalues.getmin ()?lvalues.getmin (): Rvalues.getmin ()); }}/*** Divide and conquer recursively find the maximum number of elements in an array, the minimum number *@authorAdministrator **/ Public classMinmax { Public voidMin_max (intA[],intSinte,values Values) {Values lValues=NewValues (0,0); Values rValues=NewValues (0,0); if(e==s+1| | e==s) {            if(a[s]>=A[e])                {Values.setmax (a[s]);            Values.setmin (A[e]); }            Else{Values.setmax (a[e]);            Values.setmin (A[s]); }            return; }                intMid= (e+s)/2; Min_max (A,mid+1, e,lvalues);        Min_max (a,s,mid,rvalues); Values.setmax (Lvalues.getmax ()>rvalues.getmax ()?Lvalues.getmax (): Rvalues.getmax ()); Values.setmin (Lvalues.getmin ()<rvalues.getmin ()?lvalues.getmin (): Rvalues.getmin ()); }}

Divide and conquer recursion: Find the maximum value of the array element, the minimum value

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.