Pair development--Returns the largest subarray of integer arrays and 2

Source: Internet
Author: User

Returns an integer array of maximum Subarray and 2

In order to achieve the goal of "agile development", the teacher let us take "iterative" approach to project development, this does not, for the Monday to find the largest subarray and new requirements, as follows:

1, continue the last request, here no longer redundant ...

2, if the array a[0] ... A[J-1] End-to-end connection, allow A[i-1],...... A[n-1],a[0] ... A[J-1] and the largest;

3. Returns the position of the maximum subarray at the same time;

4. The program must be able to handle 1000 elements, and each element is of type Int32.

First, experimental design ideas

The first implementation is the array end to end, the first deposit array, and then the original array is stored back into a ring array. Then the maximum number of sub-arrays, and the traversal of each number in the array to change the first number into the last digit, a new array, the calculation of each of the largest subarray in the array max[], and record the maximum sub-array position, and finally find the max[] array of the maximum value is the request.

Second, the experimental source code

1 //returns an integer array of maximum subarray and 22 //Hole Aerospace Zhao Ziyin 2016/3/253 4#include <iostream>5 using namespacestd;6 #defineN 10007 8 intValueintArry[],intlength)9 {Ten     intMax[n], max1; One     intMaxweizhi[n]; A      for(intj =0; j< (length +1) /2; J + +) -     { -         intsum =0; theMAX1 =-9999999;//set the minimum range -         intz =0; -          for(inti = j; i< (length +1) /2+ J; i++)//Ring Array to find the largest subarray and -         { +sum = sum +Arry[i]; -             if(Sum >=max1) +             { AMax1 =sum; atz++; -             } -         } -MAX[J] =max1; -MAXWEIZHI[J] =Z; -  in     } -     intFmax = max[0]; to     intQ =0; +      for(inti =0; i< (length +1/2); i++)//find the maximum value in all and arrays -     { the         if(max[i]>Fmax) *         { $Fmax =Max[i];Panax NotoginsengQ =i; -         } the     } +  A     intWeizhi =Maxweizhi[q]; the  +cout <<"the maximum number of sub-arrays is:"<<Endl; -      for(intnum = q; Num<q + Weizhi; num++)//the position of the output maximum sub-array $     { $cout << Arry[num] <<" "; -     } -  thecout <<"its and is:"<< Fmax <<Endl; -     return 0;Wuyi } the  - voidMainintargcChar*argv[]) Wu { -     intArry[n]; About     intLength =1; $     intMax[n], max1;//Max[n] The result of each summation, in which the maximum value is found, for the -     intMaxweizhi[n]; -     intnum =0; -     intValueintArry[],intlength); Acout <<"Please enter an array:"<<Endl; +CIN >> arry[0]; the      while(GetChar ()! ='\ n')//Input Array -     { $CIN >>Arry[length]; thelength++; the     } the  the      for(intj = length; j<2* Length-1; J + +)//form a ring array, the first connected -     { inARRY[J] =Arry[num]; thenum++; the     } About  thecout <<"An array of rings formed by these several numbers"; theValue (Arry,2* Length-1); the  +}

The experiment is as follows:

Third, the experience of experimental experiences

Through these several pairs of development, let me know that the software development process, whether it is a pair or team work will be more efficient than one person's productivity. We are not the so-called "thigh-hugging" people, so in the team we can learn from each other's good ideas to enrich themselves, so still a little look forward to the future team cooperation.

In this experiment, how to achieve the "end-to-end" of the array I and the hole students think of a lot of ideas, including several ideas that we have written executable files, including: Expand twice-fold array, dynamic planning, define the start and end position, etc. But when we think about outputting the position of the largest sub-array, we only add this function to this idea. Although there have been many attempts at last failed, but we have to learn to enjoy the fun, right? Ha!

Pair development--Returns the largest subarray of integer arrays and 2

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.