Perl implementation of high waterline algorithm (method for solving multi value comparison problem)

Time:2021-11-25

“High water line” algorithm: after the flood, when the last wave subsides, the high water line will mark the highest water level seen.
Let’s take a look at the application of the “high waterline” algorithm in Perl.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#! /usr/bin/perl;
use utf8;
 
sub max {
  my($max_so_far) = shift @_; #The first value in the array is temporarily regarded as the maximum value.
  foreach(@_){         #Traversal [email protected]_
  if($_>$max_so_far){     #See if other elements are better than $max_ so_ Far is a large value.
  $max_so_far = $_;}     #Update the maximum variable, if any
  }
  $max_so_far;
}
 
my $_MaxData = &max(2,3,8,5,10);
print $_MaxData;

First row pair [email protected]_ Shift an element 2 to the maximum value of $max_ so_ In the far [email protected]_ The remaining elements in the new array are (3,8,5,10), and then use the foreach loop to traverse the array. The first element in the new array is 3 larger than 2 and is moved to $max_ so_ Far variable, and so on. The last 10 is the largest element in the array.

Recommended Today

Apache sqoop

Source: dark horse big data 1.png From the standpoint of Apache, data flow can be divided into data import and export: Import: data import. RDBMS—–>Hadoop Export: data export. Hadoop—->RDBMS 1.2 sqoop installation The prerequisite for installing sqoop is that you already have a Java and Hadoop environment. Latest stable version: 1.4.6 Download the sqoop installation […]