Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi can you help me answer the following Data Structure and Algorithm Question using Java with step by step detailed solution and explanation? Thank you

Hi can you help me answer the following Data Structure and Algorithm Question using Java with step by step detailed solution and explanation? Thank you very much!

image text in transcribed

image text in transcribed

3. Assume we have Class Queue, a double-ended queue that stores integers. This class has a default constructor that you can call. It also already implements all methods defined in the following interfaces: public interface //Return the first data. //Throw Exception if the queue is empty public int front) throws Exception; MyQueue //each method is assumed to perform in e(1) //Return the last data. //Throw Exception if the queue is empty public int back () throws Exception; //Remove the first data (return its value too). //Throw Exception if the queue is empty public int removeFirst() throws Exception; //Insert new data after the last data //Throw exception if the insert fails for some reason. public void insertLast(int data) throws Exception; /Check if the queue is empty public boolean isEmpty); //Check if the queue has no more space to store new data public boolean isFull(); //Return the number of data currently stored in the queue. public int size); We are using queues in our own class TestQueue, which is Class TestQueuel Queue q1, q2; public void crossOver(int p1, int p2)X // You have to write code for this method. You are to implement method crossOver, which exchanges values stored from position p1 to q1.size)-1 of q1 with values stored from position p2 to q2.size0-1 of q2. The value of p1 and p2 is assumed to always be from 0 to q1. size0-1 and q2.size0-1 respectively For example, if q1 has 1,2,3,4,5) and q2 has (6,7,8,9,10), when crossOver(2,3) is called, q1 will then store 1,2,9,10 and q2 will store (6,7,8,3,4,5) interfaces. You are allowed to create primitive type variables. * You are not allowed to create non-primitive type variables, or any_data structure (12 marks) Draw pictures of queues in various states and explain your implementation of method crossOver (11 marks) Write code for method crossOver a. b. c. (4 marks) Show how you analyze asymptotic runtime for your code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

here) and other areas you consider relevant.

Answered: 1 week ago