小编ezg*_*gar的帖子

洪水填充算法

即时通讯使用turbo C++在C中创建一个简单的图形库,因为我开发了一个非常原始的绘画风格程序版本,每个都运行良好,但我无法使洪水填充算法工作.我使用4路洪水填充算法,首先我尝试使用递归版本,但它只适用于小区域,填充大区域使其崩溃; 阅读我发现实现它的显式堆栈版本解决了问题,但我没有真正看到它.

我开发了这样的堆栈:

struct node
{
    int x, y;
    struct node *next;
};

int push(struct node **top, int x, int y)
{
    struct node *newNode;
    newNode = (struct node *)malloc(sizeof(struct node));
    if(newNode == NULL) //If there is no more memory
        return 0;
    newNode->x = x;
    newNode->y = y;
    newNode->next = *top;
    *top = newNode;
    return 1; //If we push the element correctly
}

int pop(struct node **top, int &x, int &y)
{
    if(*top == NULL) //If the stack is …
Run Code Online (Sandbox Code Playgroud)

c algorithm primitive flood-fill graphic

1
推荐指数
1
解决办法
9893
查看次数

标签 统计

algorithm ×1

c ×1

flood-fill ×1

graphic ×1

primitive ×1