Question: class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; // top of stack //---------------------------- ---------------------------------- public StackX(int
class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; // top of stack //----------------------------
---------------------------------- public StackX(int s) // constructor { maxSize = s; // set array size stackArray = new long[maxSize]; // create array top = -1; // no items yet } //-------------------------------------------------------------- public void push(long j) // put item on top of stack { stackArray[++top] = j; // increment top, insert item } //-------------------------------------------------------------- public long pop() // take item from top of stack { return stackArray[top--]; // access item, decrement top } //-------------------------------------------------------------- public long peek() // peek at top of stack { return stackArray[top]; } //-------------------------------------------------------------- public boolean isEmpty() // true if stack is empty { return (top == -1); } //-------------------------------------------------------------- public boolean isFull() // true if stack is full { return (top == maxSize-1); } //-------------------------------------------------------------- } // end class StackX //////////////////////////////////////////////////////////////// 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; } //-------------------------------------------------------------- } // end class Queue //////////////////////////////////////////////////////////////// class PriorityQ { // array in sorted order, from max at 0 to min at size-1 private int maxSize; private long[] queArray; private int nItems; //------------------------------------------------------------- public PriorityQ(int s) // constructor { maxSize = s; queArray = new long[maxSize]; nItems = 0; } //------------------------------------------------------------- public void insert(long item) // insert item { int j; if(nItems==0) // if no items, queArray[nItems++] = item; // insert at 0 else // if items, { for(j=nItems-1; j>=0; j--) // start at end, { if( item > queArray[j] ) // if new item larger, queArray[j+1] = queArray[j]; // shift upward else // if smaller, break; // done shifting } // end for queArray[j+1] = item; // insert it nItems++; } // end else (nItems > 0) } // end insert() //------------------------------------------------------------- public long remove() // remove minimum item { return queArray[--nItems]; } //------------------------------------------------------------- public long peekMin() // peek at minimum item { return queArray[nItems-1]; } //------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return (nItems==0); } //------------------------------------------------------------- public boolean isFull() // true if queue is full { return (nItems == maxSize); } //------------------------------------------------------------- } // end class PriorityQ
Instructions: Above is the program my teacher wanted us to copy and paste and make modifications to it according to the following problem:
Stack class is for Scretary Queue class is for Clerk 1 Priority class is for Clerk 2 Create constructor with parameters (int a, int b, int c): A & B is a number between 1-50 and C is a number between 1-2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
