Create a second empty queue q2

Assignment Help Data Structure & Algorithms
Reference no: EM132087306

Here is the 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 an 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

Reference no: EM132087306

Questions Cloud

What is the average density of the mixture : How van I find the average density of the mixture; then 40 cm3 of gasoline are mixed with 50 cm3 of water. What is the average density of the mixture?
Setting pco2 to an absurdly high value : Setting pCO2 to an absurdly high value of 10,000 ppm, you will see a spike in the CO2 absorption band.
What are the benefits of using encryption : What implications would follow from not using cryptological technologies? Why might vendors propose proprietary encryption methods?
Calculate the equilibrium pressures of all species : If pure phosgene at an initial pressure of 1.0 atmosphere decomposes, calculate the equilibrium pressures of all species.
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.
Calculate the energy : Afterwards he feels guilty and decides to work off the excess calories by walking up 6 flights of stairs 3 times. Calculate the energy.
What is the overall structure of a dna molecule : What is the overall structure of a DNA molecule What is chemistry
Why do you the organization choose to use virtual desktop : Why do you the organization choose to use virtual desktop it's users?
The process of migrating to a newer enterprise resource : Your organization is in the process of migrating to a newer enterprise resource planning application.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd