Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions For this homework I would like you to refer to the following UML: A

ID: 3874474 • Letter: I

Question

Instructions For this homework I would like you to refer to the following UML: ArrayQueue size int CAPACITY int data [] E + ArrayQueue () + dequeue() E enqueue (input E): void + isEmpty ) boolean t peek): E Question 1: In a Word document I would like you create the algorithm for each of the member methods listed in the UML. Remember that your algorithm's need to list the pre/post conditions (i.e., the queue isn't empty) and then you need to check for that condition (if size equals 0). Also, d the step-wise refinement. Write your steps in a bulleted list. Then for each list item, see if it is a clear and complete statement, can you ask "how"? If so, you need to add a little more detail Question 2: After creating the algorithms for your methods I would like you to create the pseudocode for each algorithm

Explanation / Answer

ArrayQueue() shall be used for initalization purpose only

dequeue()
Step 1: If isEmpty() is true, throw error indicating underflow and return
Step 2: Let 1st element of data array copied to temp. (tmp = data[0])
Step 3: Left shift the data array by 1 element so that the 1st item in the array is discarded
Step 4: Decrement size by 1
Step 5: Return tmp


enqueue (dataItem)
Step 1: If size = CAPACITY then throw error indicating overflow and return
Step 2: Copy input dataItem to index position size of the data array
Step 3: Increment size by 1
Step 4: Stop

isEmpty()
Step 1: if size = 0 return true else return false

peek()
Step 1: If isEmpty() is true, throw error indicating underflow and return
Step 2: Let 1st element of data array copied to temp. (tmp = data[0])
Step 3: Return tmp

pseudocode:

E dequeue() {
   if (isEmpty())
       throw underflow;

   E tmp = data[0];
   for i = 1 to size
       data[i-1] = data[i];
   size = size - 1;
   return size
}

void enqueue(E dataItem) {
   if (size == CAPACITY)
       throw overflow;

   data[size] = dataItem;
   size = size + 1;
}

boolean isEmpty () {
   return size == 0;
}

E peek() {
   if (isEmpty())
       throw underflow;

   return data[0];
}