Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Assignment

You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List - that will technically make it a queue).

You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1). When creating your Queue object use the correct function names for enqueue and dequeue functions.

Again - sorry, cannot use a Javascript array in your implementation - you need to implement enqueue and dequeue.

Create a second empty Queue Q2.

Once you have the first Queue filled we are going to use a technique called Sieve of Eratosthenes which uses first queue to fill the second queue.

Here is the algorithm;

1. Dequeue 1st element in Q1 (which will be 2). You will need to remember the value of this element - we will call it X.

2. Enqueue this element into Q2 (Q2 is the list of primes)

3. Iterate and Dequeue each successive element of Q1

If the value is divisible by X, go to the next element

if the value is not divisible by X enqueue back onto Q1, go to the next element.

4. Print the values of Q1 and Q2 after each time through.

5. When done go back to the beginning of the Q1 and repeat steps 1-3 (the first value will be 3 the second time around)

Sample output with input 10

Iteration 0: Q1 = 2 3 4 5 6 7 8 9 10, Q2 = ,

Iteration 1: Q1 = 3 5 7 9, Q2 = 2

Iteration 2: Q1 = 5 7, Q2 = 2 3

Iteration 3: Q1 = 7, Q2 = 2 3 5

Iteration 4: Q1 = , Q2 = 2 3 5 7

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93068879

Have any Question?


Related Questions in Computer Engineering

What effect does the teacher have on creating a learning

What effect does the teacher have on creating a learning environment with little to no behavior problems?

Question suppose that in responding to interrupts from an

Question : Suppose that in responding to interrupts from an I/O device the processor consumes 1000 cycles in performing the context switch required to transfer control to the interrupt handler. Servicing the device reque ...

What is the difference between dekkers algorithm and igloo

What is the difference between Dekkers Algorithm and Igloo approach? Please provide examples that can explain this.

Assignment week 3 create a scrum boardprojects that conform

Assignment: Week 3 Create a Scrum Board Projects that conform to the Agile methodology often use something called a scrum board. You can think of a scrum board as a digital whiteboard containing yellow "stickies," each l ...

Question you are required to sort a file containing

Question : You are required to sort a file containing integers between 0 and 999999. You cannot afford to use one million pigeon-holes, so you decide instead to use one thousand pigeon-holes numbered from 0 to 999. You b ...

Directionspick one topic for word and one topic

Directions Pick one topic for Word and one topic for PowerPoint to discuss. Word Watermark: What is the purpose of watermark for a document? What do you consider when you work on a watermark in Word? Newsletter: What are ...

Problem belowwrite a program that uses a function that

Problem below: Write a program that uses a function that returns a number between 1 and 6. Use this function to simulate the roll of a die. Allow the user to specify the number of trials and then tabulate that number of ...

Now assume that this market becomes perfectly competitive

Now, assume that this market becomes perfectly competitive. The production process for the good does not change. So, all firms have the same cost curves as the monopolist. Reference from: Q3. A monopolist in the sugar ma ...

Shell scripting -- linuxpart-1 write a script that asks the

Shell Scripting -- Linux Part-1 Write a script that asks the user to enter his name. Read the name. Then asks the user to enter the phone number. Then read the phone number. Append the name and phone number (separated by ...

Question please research a professional white paper

Question: Please research a professional white paper (academic) PDF format and with in the last two years that is relevant to this class and outline a 750 word document in APA format include the following: cover sheet, i ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As