Results 1 to 4 of 4
  1. #1
    bap2 is offline Member
    Join Date
    Oct 2010
    Posts
    20
    Rep Power
    0

    Default Need help with array queue

    I am not sure about what to do with the queue method any suggestions or corrections?

    Here is the code for the JFQueue interface
    Java Code:
    public interface JFQueue
    {
        /**
         * @praram s is a string to be added to the queue
         * @return true if new element is successfully added, false otherwise
         */
        public boolean queue(String s);
    
        /**
         * deletes the element in the head of first position of the queue
         * @return the value of the deleted element
         */
        public String deQueue();
    }
    Here is what I have so far for the queue
    Java Code:
    public class ArrayQueue implements JFQueue
    {
        private int maxSize; //maximum queue size
        int head; //location of the head or first element
        int tail; //location of the last element
        int size; //number of elements in the queue
        String[] data; //array to hold the data
    
        /**
         * Constructor
         * @param maxSize sets up the maximum queue size
         */
        public ArrayQueue(int maxSize)
        {
            this.maxSize = maxSize;
            head = 0;
            tail = 0;
            data = new String[maxSize];
            for(int i=0; i<maxSize; i++)
            {
                data[i] = null;
                size = 0;
            }
        }
        
        //Add an element to the end of the queue
        public boolean queue(String s)
        {
            if(size == 0)
            {
                head = tail;
                tail = 0;
                size++;
                return false;
            }
            
            if(size == maxSize)
            {
                expand();
            }
            
            if(size < maxSize)
            {
                compact();
            }
            
            size++;
            int n = (tail + 1) ___"I don't know what should go here"___;
            data[n] = s;
            tail = n;
            return true;
        }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    Well, does it work?
    If not, what is the problem?

  3. #3
    bap2 is offline Member
    Join Date
    Oct 2010
    Posts
    20
    Rep Power
    0

    Default

    Right now it does not work. This is just as far as i have gotten on the code. Where I put "I don't know what should go here" is the part of the code I am having trouble figuring out what I should put in order to get it to work.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    What does "does not work" mean?
    I'm not going to compile and run this, you know...

Similar Threads

  1. Queue
    By DCY in forum New To Java
    Replies: 6
    Last Post: 05-04-2010, 09:07 PM
  2. Queue in the GUI
    By jonywalker123 in forum Advanced Java
    Replies: 2
    Last Post: 03-06-2009, 09:33 PM
  3. Declaring a Queue
    By rhm54 in forum New To Java
    Replies: 1
    Last Post: 03-21-2008, 06:02 AM
  4. Help with queue array please!!
    By vmcg105 in forum New To Java
    Replies: 1
    Last Post: 03-08-2008, 08:03 PM
  5. Using a queue
    By Krmeus in forum New To Java
    Replies: 0
    Last Post: 12-10-2007, 04:38 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
  •