6 questions. Covers Explicit stack in Python.
Questions 1 to 5 of 6
while stack:
fill_stack
Use the arrows to put the steps in order.
python stack = [] stack.append(4) stack.append(9) print(stack.pop()) stack.append(2) print(len(stack)) while stack: print(stack.pop())
python DR = [-1, 1, 0, 0] DC = [0, 0, -1, 1] def fill_stack(grid, start_r, start_c, new_color): old_color = grid[start_r][start_c] if old_color == new_color: return stack = [(start_r, start_c)] while stack: r, c = stack.pop() if r < 0 or r >= len(grid) or c < 0 or c >= len(grid[0]): continue if grid[r][c] != old_color: continue grid[r][c] = new_color for d in range(4): stack.append((r + DR[d], c + DC[d])) grid = [[1, 2, 1], [1, 1, 0]] fill_stack(grid, 0, 0, 3) print(grid)
DR
DC
python stack = [(start_r, start_c)] while stack: r, c = stack.pop() if grid[r][c] != old_color: continue if r < 0 or r >= len(grid) or c < 0 or c >= len(grid[0]): continue grid[r][c] = new_color for d in range(4): stack.append((r + DR[d], c + DC[d]))
grid[r][c]
3 question(s) left on this page.