Results 1 to 7 of 7
  1. #1
    aceoraiz is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default 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. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    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.
    Do you understand that much? If not, please ask a question about what you don't understand.

    -Gary-

  3. #3
    aceoraiz is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    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. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    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
    Now let's add 'h':
    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. #5
    aceoraiz is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

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

    Default

    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. #7
    aceoraiz is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    i tested on last night and i kinda get what you mean now... thanks sir gary :D

Similar Threads

  1. Replies: 9
    Last Post: 09-21-2010, 05:15 PM
  2. WORD Translation HELP PLZ :(
    By sammypants in forum New To Java
    Replies: 2
    Last Post: 11-24-2009, 02:46 PM
  3. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM
  4. Word
    By right2001 in forum New To Java
    Replies: 2
    Last Post: 04-07-2009, 04:25 AM
  5. Word OLE
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 03:33 PM

Posting Permissions

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