Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBsortI.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include "CTBgrab.hxx"
00015 
00025 
00026 
00027 template <class T, class C>
00028 inline void CTBsortI<T,C>::operator()(CTBvector<T>& v)
00029 {
00030   CTBgrab<T>  grab;
00031   C           compare;
00032   T           tmp;
00033   
00034   for (CTBint i = 1; i < v.Size(); i++) {
00035     grab(tmp,v[i]);
00036     CTBint j = i-1;
00037     
00038     while (j >= 0 && compare(tmp,v[j])) {
00039       grab(v[j+1],v[j]);
00040       j -= 1;
00041     }
00042     grab(v[j+1],tmp);
00043   }
00044   
00045   return;
00046 }
00047 
00048 //------------------------------------------+-----------------------------------
00050 
00051 template <class T, class C>
00052 inline void CTBsortI<T,C>::operator()(CTBvector<CTBint>& ind, 
00053                                       const CTBvector<T>& v)
00054 {
00055   C      compare;
00056   
00057   ind.Resize(v.Size());
00058   for (CTBint i = 0; i < v.Size(); i++) ind[i] = i;
00059   
00060   for (CTBint i = 1; i < v.Size(); i++) {
00061     CTBint tmp = ind[i];
00062     CTBint j   = i-1;
00063     
00064     while (j >= 0 && compare(v[tmp],v[ind[j]])) {
00065       ind[j+1] = ind[j];
00066       j -= 1;
00067     }
00068     ind[j+1] = tmp;
00069   }
00070   
00071   return;
00072 }

Generated at Fri Oct 24 18:11:30 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001