Looking for the longest continuous monotonous propringe sequence with two bibarry

xiaoxiao2021-03-14  214

/ * In a sequence consisting of N numbers, the longest monotonous junction sequence is found. The subsequence is continuous * /

#include using namespace std;

template void ArrCopy (const T arrSource [], const int & startPosition, T * & arrDestination, const int & count) {// from the array arrSource first startPosition start copying count number of elements in the array arrDestination if (arrDestination) { Delete [] arrdestination; arrdestination = 0;} arrdestination = new t [count]; int pos = 0; for (int i = startposition; i

Template Void Printarr (Const T Arr [], Const Int & Size {// Output array element for (int i = 0; i

Template Void getMaxIncSubarr (Const T Arr [], // Source Sequence Const INT & SUB, // Generate Subset INT & Subsize // Subset Length {IF (SIZE <= Subsize) {return;}

/ / Determine the value of Tempsubsize

INT TEMPSUBSIZE = 1;

INT POINTER = SIZE >> 1; // Pointer pointing the middle of the source sequence (Pointer 1 Arr [Pointer]) {// If the number of Pointer is greater than the number pointed to by Pointer , Pointer right shift, Tempsubsize self-increasing Tempsubsize; Pointer;

Pointer = size >> 1; // Indicator Refers to the middle of the source sequence (Pointer> 0 && Arr [Pointer-1]

IF (Tempsubsize> Subsize) {// If this subsequence is longer than previously found subsets, updates Subsize Subsize = Tempsubsize; Arrcopy (Arr, Pointer, Sub, Subsize);

INT * LEFT = 0; // Left is the left portion INT LEFTSIZE = Pointer; if (Leftsize> subsize) {Arrcopy (Arr, 0, Left, Leftsize);}

INT * Right = 0; // Right is the right part of the single-tuning propriety sequence in the middle of the source sequence, INT RIGHTSIZE = Size - Pointer - Subsize; IF (Rightsize> Subsize) {Arrcopy (Arr, Pointer Subsize, Right Rightsize);

IF (Pointer> Subsize) {// Calculate the longest single-tuning probing gem sequence on the left part GetMaxIncSubarr (LEFT, LEFTSIZE, SUB, SUBSIZE); Delete [] LEFT;} if (Rightsize> Subsize) {// Calculated on the right part The longest monotonized junction sequence GetMaxIncSubarr (Right, Rightsize, Sub, Subsize); delete [] right;}}

INT Main (int Argc, char * argv []) {int Arr [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int size = sizeof (arr) / sizeof int * sub = 0; int subsize = 0; getMaxincsubarr (Arr, size, sub, subsize); cout << Subsize << Endl; Printarr ; delete [] SUB ;

cin.get (); return 0;

转载请注明原文地址:https://www.9cbs.com/read-129385.html

New Post(0)