Each time the Each time the program decides program decides to place a queen to place a queen on the board, on the board, the position of the position of the new qu[r]
Trang 1Chapter 7 introduces the stack data type
Several example applications of stacks are given in that chapter.
This presentation shows another use called
backtracking to solve the NQueens problem
Data Structures
and Other Objects
Using C++
Trang 2chess queens
and a chess board
Trang 3placed on the board so
that no two queens are
attacking each other
?
Trang 4allowed in the same
row
Trang 5allowed in the same
row, or in the same
column
Trang 6allowed in the same
row, or in the same
column, or along the
same diagonal
Trang 7and the size of the board
can vary
ws
N columns
Trang 8which tries to find a way
to place N queens on an
N x N chess board
Trang 9uses a stack to
keep track of
where each
queen is placed
Trang 10program decides
to place a queen
on the board,
the position of
the new queen is
stored in a
record which is
placed in the
stack
ROW 1, COL 1