CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Queue.java

  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Post Queue.java

    Given the program, dbug and modify the application to acquire the following outputs:
    40 50 60 70 80
    70 80 10 20 60
    80 40 50 60 70 80
    40 50 60 70 80 40
    50 60 70 80 40

    import java.io.*;
    class Queue
    {
    private int[] queArray;
    private int front;
    private int rear;
    private int nItems;
    //----------------------------------
    public Queue(int s)
    {
    maxSize=s;
    queArray=new int[maxSize];
    fron=0;
    rear=-1;
    nItems=0;
    }
    //---------------------------------
    public void insert (int j)
    {
    if(rear==nItems-1)
    rear=-1;
    queArray[++rear]=j;
    nItems;
    //------------------------------------
    public int remove()
    {
    int temp=queArray[rear++];
    if(front==maxSize)
    rear=0;
    niTems--;
    return temp;
    }
    //--------------------------------------
    public int peekFront()
    {
    return queArray[fron];
    }
    public boolean isEmpty()
    {
    return (maxSize==0);
    }
    //---------------------------------------
    public boolean isFull()
    {
    return (nItems==maxSize);
    }
    //----------------------------------------
    public int size()
    {
    return nItems;
    }
    //----------------------------------------
    class QueueApp
    {
    public static void main(String[]args)
    {
    Queue theQueue=new Queue(5);

    theQueue.insert(10);
    theQueue.insert(20);
    theQueue.insert(30);
    theQueue.insert(40);

    theQueue.remove();
    theQueue.remove();
    theQueue.remove();

    theQueue.insert(50);
    theQueue.insert(60);
    theQueue.insert(70);
    theQueue.insert(80);

    while(!theQueue.isEmpty())
    {
    int n=theQueue.remove();
    System.out.print(n);
    }
    System.out.println(" ")
    }
    }

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Queue.java

    First off, you really need to use the code tags when placing your code up so we can read it.

    Secondly, do you actually have a question, or did you want us to do your homework for you? What part of the program don't you understand?

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured