When March 2015
This algorithm will find the maximum and minimum value of an generic typed array.
This algorithm will begin with a generically typed interface with min and max methods.Next the class of type T will be extended by the comparable class to compare the values in the array and will implement the methods in the interface above.We will first create the instance of the class object.
The min algorithm will follow these steps
The max algorithm will follow these steps
Results
The results for this code can be found at
More info
The source code for this algorithm can be found at
This algorithm will find the maximum and minimum value of an generic typed array.
This algorithm will begin with a generically typed interface with min and max methods.Next the class of type T will be extended by the comparable class to compare the values in the array and will implement the methods in the interface above.We will first create the instance of the class object.
The min algorithm will follow these steps
- Set the default min value to the first entry of the array.
- iterate through the indices of the array from i equal to 0 to length of array minus 1.
- if array[i] compared to the min value is less than 0,the new min value is set to array[i]
The max algorithm will follow these steps
- Set the default max value to the first entry of the array.
- iterate through the indices of the array from i equal to 0 to length of array minus 1.
- if array[i] compared to the max value is greater than 0,the new max value is set to array[i]
Results
The results for this code can be found at
- https://github.com/michaelrizzo2/Programming-Work/blob/master/java%20interface%20with%20generic%20interface/java_interface_with_generic_methods_output.txt
More info
The source code for this algorithm can be found at
- https://github.com/michaelrizzo2/Programming-Work/blob/master/java%20interface%20with%20generic%20interface/java_interface_with_generic_methods.java