Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that th
is does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that one item and no items display properly, no matter where front and rear are. Listing 4.4 is below
class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//
public Queue(int s)
{
maxSize = s;
queArray = new long[maxSize];
front =0;
rear = -1;
nItems = 0;
}
//
public void insert(long j)
{
if(rear == maxSize -1)
rear = -1;
queArray[++rear] = j;
nItems++;
}
//
public long remove()
{
long temp = queArray[front++];
if(front == maxSize)
front = 0;
nItems--;
return temp;
}
//
public long peekFront()
{
return queArray[front];
}
//
public boolean isEmpty()
{
return(nItems==0);
}
//
public boolean isFull()
{
return (nItems==maxSize);
}
//
public int size()
{
return nItems;
}
//
} //end class
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() )
{
long n = theQueue.remove();
System.out.print(n);
System.out.print( " ");
}
System.out.println(" ");
} //end main()
} //end class
4.2
Create a Deque class based on the discussion of deques (double-ended queues) in this chapter. It should include insertLeft(), insertRight(), removeLeft(), removeRight(), isEmpty(), and isFull() methods. It will need to support wraparound at the end of the array, as queues do.
4.3
Write a program that implements a stack class that is based on the Deque class in the Programming Project 4.2. This stack class should have the same methods and capabillities as the StackX class in the stack.java program (Listing 4.1).
Mobile device management is a type of security software used by an IT department to monitor, manage, and secure employees' mobile devices (laptops, smartphones, tablets, etc.) that are deployed across multiple mobile service providers and across multiple mobile operating systems being used in the organization.
Answer: When you share what the design process looks like with your client, it allows you to establish realistic project deliverables and deadlines together. Your client will know exactly what to expect from you and when to expect it, eliminating needless miscommunication later.