Question: // Remove an element from the front of the queue which is index // 0. Shift all existing elements to the left by one index.
// Remove an element from the front of the queue which is index // 0. Shift all existing elements to the left by one index. The new // front of the queue should be at index 0 after this shift. Ensure // that all empty slots have the value -1 in them. On successfully // removing an element, return true. If queue is empty (length 0 or // all elements are -1), return false. // // EXAMPLES: // int [] q = {-1, -1, -1}; // boolean result = removeFromFrontOfQueue(q); // q is now {-1, -1, -1} // result is false // // int [] q = {4, 2, -1}; // boolean result = removeFromFrontOfQueue(q); // q is now {2, -1, -1} // result is true // // int [] q = {2, -1, -1}; // boolean result = removeFromFrontOfQueue(q); // q is now {-1, -1, -1} // result is true // // int [] q = {2, 1, 9, 7, -1}; // boolean result = removeFromFrontOfQueue(q); // q is now {1, 9, 7, -1, -1} // result is true // // int [] q = {}; // boolean result = addToEndOfQueue(q); // q is now {} // result is false public static boolean removeFromFrontOfQueue(int [] queue){
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
