Im struggling to come up with code on how to find out if the queue is empty/full

I know it would be if statements but im not sure how i would go about it, any help?

Printable View

- 11-07-2008, 11:18 AMJava01Help with Queues in Java
Im struggling to come up with code on how to find out if the queue is empty/full

I know it would be if statements but im not sure how i would go about it, any help? - 11-07-2008, 11:49 AMJava01Code:
`public ArrayQ () {`

//The constructor must initiallise the class's attributes

head == 0;

tail == -1;

}

public boolean qEmpty () {

// fill in

// queue is empty if head position is bigger than tail position

if head > tail

{

qEmpty = true

else

false;

}

}

public boolean qFull () {

//fill in

//queue is full if tail position is bigger than SIZE - 2

if tail = SIZE -2

{

qFull = true

else

false;

}

}

public void qAdd(Object x) {

// fill in. check the queue is not full. Add the object in the

// right position in the queue and alter the local attributes

// appropriately

if( SIZE == data[].length )

doubleQueue( );

tail = increment( tail );

data[ tail ] = x;

SIZE++;

}

- 11-07-2008, 03:38 PMNorm
Does it compile? What do the error messags say? Do you understand them? Copy and paste them here if you need help.

- 11-07-2008, 04:56 PMCJSLMANSome observations...
Just some things that caught my eye...

- qFull & qEmpty are methods that return booleans and you're not returning anything: add the return statement.

- The comments indicate that

Code:`//queue is full if tail position is [B][U]bigger[/U][/B] than SIZE - 2`

Code:`if tail = SIZE -2`

- the if statement is incorrect because it's missing it's parentesis: if (statement)... which means that this code doesn't compile.
- Where did this pseudo code come from?

CJSL