IamNotSam 0 Newbie Poster

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.