230                                    8. :   

  (.  Kelly and Pohl, A Book on : 3rd Edition, Benjamin/
Cummings, 1995).    .

 quicksort ,    
  ,     (mid-value). 
 ,      ,     -
   .      -
 ,        ,   -
  .   quicksort 
       .

  vectsort.cpp

//QUICKSORT,  

void quicksort(vector::iterator from, vector::iterator to)
{

vector::iterator mid;

if (from < to - 1) {

mid = partition(from, to);    // 
quicksort(from, mid);         //   from  to
quicksort(mid + 1, to);       //mid  ""

}
}

vector::iterator partition(vector::iterator from,

vector::iterator to)
{

vector::iterator front = from + 1, back = to - 1;

int compare = *from;

while (front < back) {

//     ()

while ((front < back) &&(compare > *front))
++front;

//     ()

while ((front < back) &&(compare <= *back))
--back;

swap(*front, *back) ;

}

//    

if (compare > * front) {

swap(*from, *front);

return front;

}
else {

swap(*from, *(front - 1));

return front - 1;

}