954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Flood Fill Array Queue Help - Simple Problem

Hi,
I have a task which involves using a queue in order to fill an enclosed region.
For example I have chosen this 2d array to apply a flood fill technique to.

int[][] shape ={ {X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X},
                       {X,X,X,0,0,0,0,0,0,0,0,0,0,0,0,0,X,X,X,X},
                       {X,X,X,0,X,X,X,X,X,X,X,X,X,X,X,0,X,X,X,X},
                       {X,X,X,0,X,X,X,X,X,0,0,0,0,0,0,0,X,X,X,X},
                       {X,X,X,0,0,X,X,X,X,0,X,X,X,X,X,X,X,X,X,X},
                       {X,X,X,X,0,X,X,X,X,0,X,X,X,X,X,X,X,X,X,X,
                       {X,X,X,X,0,X,X,X,X,0,0,0,0,X,X,X,X,X,X,X},
                       {X,X,X,X,0,0,0,0,X,X,X,X,0,X,X,X,X,X,X,X},
                       {X,X,X,X,X,X,X,0,X,X,X,X,0,0,X,X,X,X,X,X},
                       {X,X,X,X,X,X,X,0,X,X,X,X,X,0,X,X,X,X,X,X}
                       {X,X,X,X,X,X,X,0,X,X,X,X,X,0,X,X,X,X,X,X}
                       {X,X,X,X,X,0,0,0,X,X,X,X,X,0,X,X,X,X,X,X}
                       {X,X,X,X,X,0,X,X,X,X,X,X,X,0,X,X,X,X,X,X}
                       {X,X,X,X,X,0,0,0,0,0,0,0,0,0,X,X,X,X,X,X}
                       {X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X}
 };


I want a queue that keeps track of what needs to be filled. The head of the queue initially will be shape[2][4]. I will check above and below and to the sides of the item that is in the head of the queue.
The queue has a head and a tail. So when an item is filled it is then added to the tail of the queue. The item at the head of the queue is the one that is checked. I am using two variables - head and tail - to keep track of the head and tail in the queue.
The part I am struggling with is how to add things to the tail.
For example lets say shape[2][4] is at the head of the queue. It is an X so it is then changed to a 0. Then above, below and to the sides are checked. In this case to the right and below is changed to a 0 and they are both added to the tail. The problem I have is that how do I add these two to the tail of the array I am using for the queue. I might be able to write a program that adds only one item in an iteration of a for loop but when there is two or three items in the one loop how am I supposed to differentiate them.

Can anyone help and give some advice on how to write a program that can accomplish this task. I am using two arrays to store the coordinates of the items.
So I have a rowQueue[], columnQueue[], head, tail.


Thanks in advance.

IamNotSam
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: