السلام عليكم ...
البرناج شغال عادي بس المشكلة في out put يطبع جملة زايدة وهي في كلاس QueueApp
// Queue.java
// demonstrates queue
// to run this program: C>java QueueApp
////////////////////////////////////////////////////////////////
class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//--------------------------------------------------------------
public Queue(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
//--------------------------------------------------------------
public void insert(long j) // put item at rear of queue
{
if(rear == maxSize-1) // deal with wraparound
rear = -1;
queArray[++rear] = j; // increment rear and insert
nItems++; // one more item
}
//--------------------------------------------------------------
public long remove() // take item from front of queue
{
long temp = queArray[front++]; // get value and incr front
if(front == maxSize) // deal with wraparound
front = 0;
nItems--; // one less item
return temp;
}
//--------------------------------------------------------------
public long peekFront() // peek at front of queue
{
return queArray[front];
}
//--------------------------------------------------------------
public boolean isEmpty() // true if queue is empty
{
return (nItems==0);
}
//--------------------------------------------------------------
public boolean isFull() // true if queue is full
{
return (nItems==maxSize);
}
//--------------------------------------------------------------
public int size() // number of items in queue
{
return nItems;
}
public int getrear(){
return rear;
}
//--------------------------------------------------------------
} // end class Queueimport java.util.Scanner;
class QueueApp
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
Queue theQueue = new Queue(3);
System.out.print("Enter number : ");
int x,ans;
do{
if(!theQueue.isFull()){
x=input.nextInt();
theQueue.insert(x);
}
System.out.print("\n\nAdd more input [1.yes _ 2.no] : "); ////يطبع هذه الجملة زيادة؟؟؟؟ليش
ans=input.nextInt();
}while(ans==1 && !theQueue.isFull());
System.out.print("\n\nThe front "+ theQueue.peekFront());
System.out.print("\n\nThe rear "+ theQueue.getrear());
if(theQueue.isFull()){
System.out.print("\n\nFUll");
}
else{
System.out.print("\n\n NOT FUll");}
} // end main()
}يكرر الجملة Add more input [1.yes _ 2.no : ???
