# Word problem...PROBLEM!

• 12-16-2010, 11:53 AM
aceoraiz
Word problem...PROBLEM!
Hi guys!... im having a hard time analyzing about this word problem that was given to me, can anyone help me or atleast give an idea on how to solve this?...:confused:

Word Problem---
A queue is a list that is used in a restricted way. Items are always added to the end of the list. For example, when X is added to A, B, C, the result is A, B, C, X. items can only be removed from the front of the list. In order to remove C from the list, A and B must first be removed. Write a set of methods for treating an array of character of characters as queue. It should include method for insertion and deletion. The limits of the arrays index should be defined constants of type integer.
• 12-16-2010, 12:04 PM
gcalvin
Quote:

A queue is a list that is used in a restricted way. Items are always added to the end of the list. For example, when X is added to A, B, C, the result is A, B, C, X. items can only be removed from the front of the list. In order to remove C from the list, A and B must first be removed.

-Gary-
• 12-16-2010, 12:22 PM
aceoraiz
nope. a friend of mine gave me this question and he wants me to solve it...
this "insertion and deletion" part of the question... im not really familliar with it.
• 12-16-2010, 12:31 PM
gcalvin
Well, a queue is a queue -- just like when you line up at the grocery store. You go to the back of the line, and they take people one at a time from the front of the line. A queue in computer science is the same thing (the problem is asking for a queue of characters, but you could just as easily have a queue of integers or Strings or any other type of Object). It starts out empty:
Code:

Then you add something to it. The problem talks about "insertion" but the only insertion for a queue is at the end. So let's say we add the character 'z' to our queue:
Code:

`z`
Code:

`zh`
Now we'll add a few more characters... 'j' 'w' and 'b':
Code:

`zhjwb`
Now let's get a character from the queue. Again, you can only get a character from the front (no cheating!) so we don't need an index like we would for an array. You just say "get" and you get the 'z' in front. Then it's gone, and you're left with:
Code:

`hjwb`
You say "get" again and you get the 'h'. Three more times and you get the 'j' the 'w' and the 'b', one by one. If you try to say "get" again, you should get an error, because there's nothing to get.

Does that much make sense?

-Gary-
• 12-16-2010, 12:49 PM
aceoraiz
yeah! now that makes sense... but what would be the right code get a character from the queue? honestly i haven't experience this "insertion and deletion" in java before...
• 12-16-2010, 12:53 PM
gcalvin
Well, in this case, "insertion" just means "put a char at the end of the queue" and "deletion" means "take a char from the front of the queue".

So let's assume we're going to make a class, and call it CharQueue. What instance variables will you need? (Hint: read the problem statement again.)

-Gary-
• 12-17-2010, 04:38 AM
aceoraiz
i tested on last night and i kinda get what you mean now... thanks sir gary :D