Exemplo n.º 1
0
int main() {
    MyQueue<int> q;
    q.add(5);
    q.add(6);
    int t = q.remove();
    cout << t << endl;
    return 0;
}
Exemplo n.º 2
0
int main()
{
    MyQueue<int> mq;
    mq.add(1);
    mq.add(2);
    mq.remove();
    mq.printAll();
    debug("Hello world!", "");
    return 0;
}
Exemplo n.º 3
0
void floodFill(string file, BITMAPFILEHEADER bh, BITMAPINFO bi, RGB *rgbGrid[], size_t x, size_t y, RGB newColor) {

    if (y >= bi.biWidth || x >= bi.biHeight) {
        cerr << " index out of bounds " << endl;
        return;
    }

    x = bi.biHeight-x-1;
    y--;

    RGB oldColor = rgbGrid[x][y];

    if (RGB_equals(oldColor, newColor)) {
        cerr << " Can't floodFill this area, because of color similarity " << endl;
        return;
    }

    PointXY currentPoint{x,y};

    MyQueue myQueue;

    size_t x1;
    size_t y1;

    do {
        x1 = currentPoint.x;
        y1 = currentPoint.y;

        while (y1 > 0 && RGB_equals(rgbGrid[x1][y1-1], oldColor)) {
            y1--;
        }

        bool spanUp = false;
        bool spanDown = false;

        while (y1 < bi.biWidth && RGB_equals(rgbGrid[x1][y1], oldColor)) {

            rgbGrid[x1][y1] = newColor;

            if (!spanUp && x1 > 0 && RGB_equals(rgbGrid[x1 - 1][y1], oldColor)) {
                PointXY p{x1-1,y1};
                myQueue.add(p);
                spanUp = true;

            } else if (spanUp && x1 > 0 && !RGB_equals(rgbGrid[x1 - 1][y1], oldColor)) {
                spanUp = false;
            }

            if (!spanDown && x1 < (bi.biHeight - 1) && RGB_equals(rgbGrid[x1 + 1][y1], oldColor)) {
                PointXY p{x1+1,y1};
                myQueue.add(p);
                spanDown = true;

            } else if (spanDown && x1 < (bi.biHeight - 1) && !RGB_equals(rgbGrid[x1 + 1][y1], oldColor)) {
                spanDown = false;
            }

            y1++;
        }

    } while (myQueue.pollFirst(currentPoint));

    writeBMP(file, bh, bi, rgbGrid);
}