1. Member
Join Date
Dec 2010
Posts
4
Rep Power
0

## 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.

2. Senior Member
Join Date
Mar 2010
Posts
952
Rep Power
7
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-

3. Member
Join Date
Dec 2010
Posts
4
Rep Power
0
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.

4. Senior Member
Join Date
Mar 2010
Posts
952
Rep Power
7
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:
Java 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:
Java Code:
z
Java Code:
zh
Now we'll add a few more characters... 'j' 'w' and 'b':
Java 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:
Java 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-

5. Member
Join Date
Dec 2010
Posts
4
Rep Power
0
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...

6. Senior Member
Join Date
Mar 2010
Posts
952
Rep Power
7
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-

7. Member
Join Date
Dec 2010
Posts
4
Rep Power
0
i tested on last night and i kinda get what you mean now... thanks sir gary :D

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•