Open
Graph Drawing
Framework

 v.2012.05
 

list_templates.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_LIST_TEMPLATES_H
00049 #define OGDF_LIST_TEMPLATES_H
00050 
00051 
00052 #include <ogdf/basic/Array.h>
00053 
00054 
00055 namespace ogdf {
00056 
00057 // sorts list L using quicksort
00058 template<class LIST>
00059 void quicksortTemplate(LIST &L)
00060 {
00061     const int n = L.size();
00062     Array<typename LIST::value_type> A(n);
00063 
00064     int i = 0;
00065     typename LIST::iterator it;
00066     for (it = L.begin(); it.valid(); ++it)
00067         A[i++] = *it;
00068 
00069     A.quicksort();
00070 
00071     for (i = 0, it = L.begin(); i < n; i++)
00072         *it++ = A[i];
00073 }
00074 
00075 
00076 // sorts list L using quicksort and compare element comp
00077 template<class LIST, class COMPARER>
00078 void quicksortTemplate(LIST &L, COMPARER &comp)
00079 {
00080     const int n = L.size();
00081     Array<typename LIST::value_type> A(n);
00082 
00083     int i = 0;
00084     typename LIST::iterator it;
00085     for (it = L.begin(); it.valid(); ++it)
00086         A[i++] = *it;
00087 
00088     A.quicksort(comp);
00089 
00090     for (i = 0, it = L.begin(); i < n; i++)
00091         *it++ = A[i];
00092 }
00093 
00094 
00095 } // end namespace ogdf
00096 
00097 #endif