Hii,
One improvement is that finding min and max can be done in a single
run, rather than calling the  findMin and findMax separately.
But yet the order is O(n);
Is there any better soln than O(n);

#include<stdio.h>
#include<limits.h>
void findExtreme(int array[],int size,int* min,int* max){
        int i;
        for(i=0;i<size;i++){
                if(array[i] > *max)*max = array[i];
                if(array[i]<*min)*min=array[i];
        }


}
main(){
        int arr[]={0,609,211,432,31,2222};
        int max=INT_MIN,min=INT_MAX;
        findExtreme(arr,sizeof(arr)/sizeof(arr[0]),&min,&max);
        printf("%d %d ",max,min);
        printf("%d",max-min);
}
~
~
~

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to