Grouping recursion: calculates the maximum, minimum, and recursive arrays of array elements.

Source: Internet
Author: User

Grouping recursion: calculates the maximum, minimum, and recursive arrays of array elements.

// Divide and conquer recursion, calculate the maximum value of the array element, the minimum value/*** Save the generated maximum value, and the minimum value * @ author Administrator **/public class Values {private int max; private int min; public Values (int max, int min) {this. max = max; this. min = min;} public int getMax () {return max;} public void setMax (int max) {this. max = max;} public int getMin () {return min;} public void setMin (int min) {this. min = min ;}/ *** grouping recursively finds the maximum number and minimum number of elements in the array * @ author Administrato R **/public class MinMax {public void min_max (int a [], int s, int e, Values values) {Values lValues = new Values (0, 0 ); values rValues = new Values (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;} int mid = (e + s)/2; min_max (a, mid + 1, e, lValues); min_max (, s, mid, rValues); values. setMax (lValues. getMax ()> rValues. getM Ax ()? LValues. getMax (): rValues. getMax (); values. setMin (lValues. getMin () <rValues. getMin ()? LValues. getMin (): rValues. getMin () ;}}/*** grouping recursion to find the maximum number of array elements, min count * @ author Administrator **/public class MinMax {public void min_max (int a [], int s, int e, Values values) {Values lValues = new Values (0, 0); Values rValues = new Values (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;} int mid = (e + s)/2; min_max (a, mi D + 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 ());}}

 

Contact Us

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.