I'm a little confused on how to even start this problem. Here's the problem:
Given a square matrix, write a program that determines the number of white blocks and total number of squares in each of the white blocks. By definition the outside boundaries of the matrix must be shaded. A block of white squares consists of all of the white squares whose side boundaries are adjacent to another white square. White squares that touch only at a diagonal point are not adjacent.
Obtain the square definition from a text file. The file should contain a square matrix composed of zeros for shaded squares and nonzero values for white squares. The matrix should be allocated from dynamic memory.
At the end of the program, print a report showing the number of white blocks and the number of squares in each.
Here's the matrix:
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 2 2 2 2 0
0 1 1 0 0 2 2 2 2 0
0 0 0 3 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 4 4 4 4 4 0 0
0 0 0 0 4 4 4 0 0 0
0 0 0 0 0 4 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
We are supposed to implement the use of stacks in this program. I'm just confused on how to use them with this problem. My first inclination is to read the matrix into a multi-dimensional array, but where do the stacks come in? We are using C, so if anyone can explain this to me a little better than the stupid book is explaining stacks and this problem to me, I would be forever indebted to them for the rest of my life! :o)
Thanks!