Answer :
Keep two variables, max and min and assign each of them as the first element of the array.
Traverse through the array and compare each element with max and min and update max and min accordingly:
if(A[i] >max) max = A[i]
if(A[i] < min) min = A[i], where A is the array and i as an index.
This procedure would require 2 * n comparisions, where n is the length of the array.
Traverse through the array and compare each element with max and min and update max and min accordingly:
if(A[i] >max) max = A[i]
if(A[i] < min) min = A[i], where A is the array and i as an index.
This procedure would require 2 * n comparisions, where n is the length of the array.