4-- machine experiment seeking minimum and maximum element sequence elements

// title machine experiment 4 - seeking maximum element sequence and the second largest element 

#include <stdio.h> 
void SecondElement (A int [], int Low, High int, max int &, int & sec) {// 
	int MID ; 
	int X1, X2, X3, X4; 
	IF (High - Low <. 1) {// less than two array elements 
		return; 
	} 
	the else IF (High - Low ==. 1) {// only two array elements 
		IF (A [Low] <A [High]) { 
			max = [High] A; 
			sec = A [Low]; 
		} 
		the else { 
			max = A [Low]; 
			sec = [High] A; 
		} 
	} 
	the else { 
		MID = (High - Low) / 2; 
		SecondElement (A, Low, MID, X1, X2); 
		SecondElement (A, MID +. 1, High, X3, X4); 
		IF (X1 <X3) { 
			max = X3; 
			IF (X1 > X4) 
				sec = X1; 
			the else
				X4 = sec; 
		} 
		the else { 
			max = X1; 
			IF (X3> X2) 
				sec = X3; 
			the else 
				sec = X2; 
		} 
	} 
} 
int main () { 
	int A [] = {1,2,3,4,5, } 6,7,8,9,10,11; 
	int n-=. 11; 
	int max, sec; 
	SecondElement (A, 0,. 1-n-, max, sec); 
	the printf ( "largest element =% d, the second largest element % D = \ n-", max, sec); 
}

  

Guess you like

Origin www.cnblogs.com/Hqx-curiosity/p/12021804.html