**NEED JAVA HELP ASAP**

santana9

Banned
Jan 19, 2003
154
0
0
Hey guys this is probably really simple so here it is. I want to display the contents of a queue from rear to front. I can only get it to display from front to rear. Here is the code that I have written for the display:

class MyQueue
{
private int maxSize;
private long numberToInsert;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//--------------------------------------------------------------
public MyQueue(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}

public void display() // displays array contents
{

if (nItems==0) { //if queue is empty displays standard message
System.out.print("The queue, rear --> front: ");
}

else if (front < rear) { // if front is less then rear
System.out.print("The queue, rear --> front: ");
for(int j=front; j<=rear; j++) // goes through queue starting at the front until it reaches the rear
{
System.out.print(queArray[j] + " "); // display it
}
System.out.println("");
}


else if (front == rear) { // if front is at the same location as rear
System.out.print("The queue, rear --> front: ");
for (int j=front; j==rear; j++)
{
System.out.print(queArray[j]); // display it // prints out single value
}
System.out.println("");
}

else if (front > rear) { // if rear less then front
System.out.print("The queue, rear --> front: ");
for (int j=front; j<=maxSize-1; j++) // starts at front goes to end of queue
{
System.out.print(queArray[j] + " "); // displays those values
}
for (int j=0; j<=rear; j++) // starts at beginning of queue until reaching front
{
System.out.print(queArray[j] + " "); // displays those values
}
System.out.println("");
}

} // end display

Basically there are four cases. If the queue is empty, front < rear, front > rear, and front = rear. Please help for I am stuck and cant get it too display properly. If you would like the whole file just send me a pm.
 

mrwiseguy

Junior Member
Mar 6, 2003
13
0
0
It all depends on how you insert into the queue.
Usaually the queue is FIFO. This is what I assume here

first find the position of the first element inserted. (this in your case is given by rear).

Cases.

1. Rear < front ----> error queue empty
2. Rear=front ---> only one element (not exactly a special case)
3. Rear > front ..

x=rear;
while (x >= front)
{
SOP(queue[x])
--x;
}

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |