목차
없음
본문내용
#include
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define AXIS_X 0
#define AXIS_Y 1
#define AXIS_Z 2
typedef struct POINT {
float x;
float y;
float z;
} POINT;
// tree node
typedef struct NODE {
struct POINT* pPivot;
struct NODE* pLeft;
struct NODE* pRight;
int axis;
} NODE;
void ClearNode(NODE* pNode) {
pNode->axis = AXIS_X;
pNode->pPivot = NULL;
pNode->pLeft = pNode->pRight = NULL;
}
void InsertToTree(NODE* pNode, POINT* pPoint) {
int bLeft = FALSE;
if(!pNode->pPivot) {
pNode->pPivot = pPoint;
return;
}
// decide where to move next
if(pNode->axis == AXIS_X) {
if(pPoint->x < pNode->pPivot->x) bLeft = TRUE;
else bLeft = FALSE;
}
else if(pNode->axis == AXIS_Y) {
if(pPoint->y < pNode->pPivot->y) bLeft = TRUE;
else bLeft = FALSE;
}
else if(pNode->axis == AXIS_Z) {
if(pPoint->z < pNode->pPivot->z) bLeft = TRUE;
else bLeft = FALSE;
}
if(bLeft == TRUE) {
if(pNode->pLeft) InsertToTree(pN
#include
#include
#include
#define TRUE 1
#define FALSE 0
#define AXIS_X 0
#define AXIS_Y 1
#define AXIS_Z 2
typedef struct POINT {
float x;
float y;
float z;
} POINT;
// tree node
typedef struct NODE {
struct POINT* pPivot;
struct NODE* pLeft;
struct NODE* pRight;
int axis;
} NODE;
void ClearNode(NODE* pNode) {
pNode->axis = AXIS_X;
pNode->pPivot = NULL;
pNode->pLeft = pNode->pRight = NULL;
}
void InsertToTree(NODE* pNode, POINT* pPoint) {
int bLeft = FALSE;
if(!pNode->pPivot) {
pNode->pPivot = pPoint;
return;
}
// decide where to move next
if(pNode->axis == AXIS_X) {
if(pPoint->x < pNode->pPivot->x) bLeft = TRUE;
else bLeft = FALSE;
}
else if(pNode->axis == AXIS_Y) {
if(pPoint->y < pNode->pPivot->y) bLeft = TRUE;
else bLeft = FALSE;
}
else if(pNode->axis == AXIS_Z) {
if(pPoint->z < pNode->pPivot->z) bLeft = TRUE;
else bLeft = FALSE;
}
if(bLeft == TRUE) {
if(pNode->pLeft) InsertToTree(pN
소개글