#include <iostream>
using namespace std;
struct POINT
{
int x;
int y;
};
enum
{
UP, LEFT, DOWN, RIGHT
};
int matrix[8][8]; // 将要遍历的矩阵
POINT cp; // 当前访问的矩阵上的点
int tmp = 1; // 计数
void move( int direction )
{
switch( direction )
{
case UP: // 向上移动
cp.x = cp.x - 1;
break;
case DOWN: // 向下移动
cp.x = cp.x + 1;
break;
case LEFT: // 向左移动
cp.y = cp.y - 1;
break;
case RIGHT: // 向右移动
cp.y = cp.y + 1;
break;
}
matrix[cp.x][cp.y] = tmp ; // 在新到达的点上标记
tmp = tmp + 1; // 下一个到达的点的标记
}
void hilbert_curve( int level, int direction = UP ) // 希尔伯特遍历函数
{
if ( level == 1 )
{
switch (direction)
{
case LEFT:
move(RIGHT);
move(DOWN);
move(LEFT);
break;
case RIGHT:
move(LEFT);
move(UP);
move(RIGHT);
break;
case UP:
move(DOWN);
move(RIGHT);
move(UP);
break;
case DOWN:
HilbertCurve 希尔伯特遍历的递归实现
最新推荐文章于 2022-07-24 12:19:09 发布