static void solveMaze(void) { int x, y, offset; for (y = 0; y < height; y ++) for (x = 0; x < width; x ++) maze[y][x].visited = false; y = 0; x = 0; while (y != height - 1 || x != width - 1) { draw(x, y, true); maze[y][x].visited = true; if (!maze[y][x].right && !maze[y][x + 1].visited) { dp.addLast(offset(x + 1, y)); maze[y][x + 1].from = 1; } if (!maze[y][x].bottom && !maze[y + 1][x].visited) { dp.addLast(offset(x, y + 1)); maze[y + 1][x].from = width; } if (x > 0 && !maze[y][x - 1].right && !maze[y][x - 1].visited) { dp.addLast(offset(x - 1, y)); maze[y][x - 1].from = -1; } if (y > 0 && !maze[y - 1][x].bottom && !maze[y - 1][x].visited) { dp.addLast(offset(x, y - 1)); maze[y - 1][x].from = -width; } if (dp.getLast() == offset(x, y)) { draw(x, y, false); dp.removeLast(); } offset = dp.getLast(); x = xcoord(offset); y = ycoord(offset); } draw(width - 1, height - 1, true); }
int main() { int maxSize = 5; Deque *dq = new Deque(maxSize); dq->insert(3,1); dq->insert(4,2); dq->insert(10,1); dq->insert(20,1); dq->insert(33,2); dq->insert(333,1); dq->displayDeque(); cout << "First in deque: " << dq->getFirst() << endl; cout << "Last in deque: " << dq->getLast() << endl; cout << "Removed: "; while(!dq->isEmpty()) { cout << dq->remove(1) << " " << dq->remove(2) << " "; } cout << endl; delete dq; return 0; } // end main()