Results 1 to 7 of 7
Thread: Word problem...PROBLEM!
- 12-16-2010, 10:53 AM #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.
- 12-16-2010, 11:04 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Do you understand that much? If not, please ask a question about what you don't understand.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, 11:22 AM #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.
- 12-16-2010, 11:31 AM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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:
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:
Now let's add 'h':Java Code:z
Now we'll add a few more characters... 'j' 'w' and 'b':Java Code:zh
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:zhjwb
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.Java Code:hjwb
Does that much make sense?
-Gary-
- 12-16-2010, 11:49 AM #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...
- 12-16-2010, 11:53 AM #6
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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, 03:38 AM #7
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Can anyone see the problem with my code? problem understanding switch (newbish)
By keith in forum New To JavaReplies: 9Last Post: 09-21-2010, 04:15 PM -
WORD Translation HELP PLZ :(
By sammypants in forum New To JavaReplies: 2Last Post: 11-24-2009, 01:46 PM -
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 06:12 AM -
Word
By right2001 in forum New To JavaReplies: 2Last Post: 04-07-2009, 03:25 AM -
Word OLE
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks