Search Results for 'sort'

ATOM Icon

1 POSTS

  1. 2009/09/02 STL를 이용한 Sorting by chungki

STL를 이용한 Sorting

STL를 이용하면 간단하게 Sorting기능을 구현할 수 있다. 다음은 Point데이터를 X축기준으로 Sorting하는예제이다.
#include   
  
struct SPOINT3d  
{  
public:  
  
     SPOINT3d() {}  
     SPOINT3d(double _x, double _y, double _z) : x(_x), y(_y),z(_z) {}  
  
public:  
  
     double x;  
     double y;  
     double z;  
};  
  
typedef std::vector      pointsettype;  
  
// Sort연산자 구조체  
struct XSorter  
{  
     bool operator(const SPOINT3d& p1, const SPOINT3d& p2)  
     {  
           return (p1.x 여기서 조건문을 바꾸면 y,z기준으로 혹은 역방향으로 Sorting이 가능하다.  
     }  
};  
  
void main()  
{  
     pointsettype TPointSet;  
  
    // 데이터 삽입  
    TPointSet.push_back(SPOINT3d(0., 0., 0.));  
    TPointSet.push_back(SPOINT3d(1., 0., 0.));  
    TPointSet.push_back(SPOINT3d(2., 0., 0.));  
    TPointSet.push_back(SPOINT3d(3., 0., 0.));  
    TPointSet.push_back(SPOINT3d(4., 0., 0.));  
  
     // Sorting  
     std::sort(TPointSet.begin(), TPointSet.end(), XSorter());  
       
}  

Posted by chungki

2009/09/02 10:14 2009/09/02 10:14
,
Response
No Trackback , No Comment
RSS :
http://www.chungki.net/tc/rss/response/284


블로그 이미지

Nice !!!!!!!!

- chungki

Notices

Archives

Authors

  1. chungki

Calendar

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Site Stats

Total hits:
73376
Today:
7
Yesterday:
20