< Algorithms
Top, Chapters: 1, 2, 3, 4, 5, 6, 7, 8, 9, A
This is a source for teaching someone for different language of programming language. Find max is the topic.
Method Orange
if the tb length is 1 then
output the zero is index of array tb;
else if the tb length is 0 then
output 0;
define variable call o_intMax ( integer type);
o_intMax become tb[indexInd];
looping from 1 to (tb's length - 1) save the index into variable indexInt
if tb[indexInt] > maxInt then
maxInt become tb[indexInt];
end if
end loop
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | c | Python |
|---|
Method Apple
if input_array size is 0 then
return 0
end if
if input_array size is 1 then
return input_array[0]
end if
if input_array size is 2 then
if element zero is bigger than element one then
return element zero
else
return element one
end if
end if
create a array call aryA and the size is (input_array size divide 2)
create a array call aryB and the size is (input_array size - aryA size)
looping from zero to (input_array size / 2),
aryA[loopIndex] = input_array[loopindex]
loopindex = loopindex + 1;
end looping
define integer variable call intK, initial it the zero
looping from (aryA size) to input_array size
aryB[intK] = input_array[loopIndex]
loopindex = loopindex + 1
intK = intK + 1;
end loop
create a variable call intM
create a variable call intN
intM = run findMax(aryA);
intN = run findMax(aryB);
if intM > intN then
return intM
else
return intN
end if
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | Python |
|---|
Method Pear
Algorithm
Method findMax(i_aryTab,int i_start,int i_end)
if ( i_end - start equal one then
if ( i_aryTab[i_end] > i_aryTab[i_start] )
return i_aryTab[i_end]
else
return i_aryTab[i_start]
end if
define variable call intJ
intJ :=( (i_end - i_start ) + 1 ) / 2 - 1
define variable call oMaxN
define variable call oMaxM
oMaxN = findMax(i_aryTab,i_start,i_start+intJ)
oMaxM = findMax(i_aryTab,i_start + intJ + 1,i_end)
if ( oMaxN > oMax M )
return oMaxN
else
return oMaxM
Method findMaxHandler(i_aryTab)
return findMax(i_aryTab,0,i_aryTab.length - 1)
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | Python |
|---|
Method 4
Algorithm
Method : findMax
make all the element of input_array = mulitple itself -1; run findMin(input_array) put result into o_Max; return o_Max * -1;
Method : findMin
put to element[0] into min
for index = 1 to arraysize -1
if ( element[index] < min ) then
min = elemnt[index];
end if
end loop
return min
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | Python |
|---|
Method 5
Algorithm
Method : sorting
define p_blnFound As boolean type; p_blnFound := true; while ( p_blnFound is true ) do begin p_blnFound := false; for loop from zero to( array size - 2 ) do if ( inputArray[index] bigger than inputArray[index+1] ) then swap inputArray[index] and inputArray[index + 1]; p_blnFound := true; end if end for loop end while loop return input_array;
Method : findMax
inputArray = sorting(inputArray); return the last element of inputArray;
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | Python |
|---|
Method 6
Algorithm
Method : findMaxFourEle ( intA,intB,intC,intD)
int max = intA;
if intB > max then
begin
max = intB;
end if
if intC > max then
begin
max = intC;
end if
if intD > max then
begin
max = intD;
end if
return max;
Method: findMaxThreeEle(intA,intB,intC)
return findMaxFourEle(intA,intB,intC,intC);
NOTE: This method can be used with Method Pear
| Java | Vbscript | Java script | JScript | Visual basic | pascal | oracle sql | Perl | Php | Python |
|---|
More data will be coming soon...
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.