Write a function called sparsify that takes a boolean n by n 2-dimensional array A and returns the equivalent, sparse representation B. Use the following function header for your function:
Implement the Queue class using an array to store the items in the queue. Specifically, use a 1-dimensional integer array called data to store the items. Also, use two integer variables front and back to keep track of the front and the back of the queue. In particular, the oldest item (the one that was inserted earliest) in the queue would be in the slot whose index is front and the youngest item (the one that was inserted most recently) in the queue would be in a slot whose index is back. In general, if we read items in data starting from the index front and moving towards the index back, we would encounter items in the order in which they were inserted into the queue.
If you are not careful, it is quite possible to believe that array data is full, even when it is not. For example, suppose data is an array of size 3. Consider the sequence of operations: insert 5, insert 7, delete, insert 2, delete. At this time, the Queue has only one item and this is occupying the last slot (slot number 2) of the array. What happens if the next operation is an insert operation? Since there is no slot after the slot that back is pointing to, should we just claim that the Queue is full? No, we should just wrap around and insert the new item in slot 0 and continue in this manner.
Make sure that you do resize the array data (by doubling it) when the Queue is really full and an insert operation is performed.