Algorithm
Development Kit 1.0

algs.model.array
Class MedianSelector

java.lang.Object
  extended by algs.model.array.MedianSelector
All Implemented Interfaces:
IPivotIndex

public class MedianSelector
extends java.lang.Object
implements IPivotIndex

Select median of first/middle/last.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
MedianSelector()
           
 
Method Summary
 int selectPivotIndex(java.lang.Comparable[] ar, int left, int right)
          Compute median of three elements, ar[left], ar[mid], ar[right] to use as the pivot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MedianSelector

public MedianSelector()
Method Detail

selectPivotIndex

public int selectPivotIndex(java.lang.Comparable[] ar,
                            int left,
                            int right)
Compute median of three elements, ar[left], ar[mid], ar[right] to use as the pivot.

Specified by:
selectPivotIndex in interface IPivotIndex
Parameters:
ar - base array of elements.
left - left index of sub-array
right - right index of sub-array
Returns:
an integer index value in the range [left,right] around which to pivot.

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.