Create a list and simply implement enqueue and dequeue

Assignment Help Data Structure & Algorithms
Reference no: EM132081405

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

Reference no: EM132081405

Questions Cloud

Bankruptcy abuse prevention and consumer protection act : Bankruptcy Abuse Prevention and Consumer Protection Act (BAPCPA). Who is this law intended to help?
Write a program that will generate random numbers : Write a C++ program that will generate random numbers between the ranges of your own choice and within the random numbers, indicate the maximum, minimum.
Advantage of adr clause : One advantage of this ADR clause would be that the arbitrator's decision would not be binding on Avid.
Owner of a small retailing business : Walton, Sr., the sole owner of a small retailing business, was attempting to purchase some goods on credit from a manufacturer with whom
Create a list and simply implement enqueue and dequeue : You can create a list and simply implement enqueue and dequeue functions in the List - that will technically make it a queue.
How much of her first payment goes to pay : How much of her first payment goes to pay down the debt?
Emotions and decision making : Emotions and decision making should all emotions and feeling be removed from decision making.
Need all of these to be in a dynamic linked library : You need all of these to be in a Dynamic Linked Library. All You need is the Classes for each and methods below.
What matters do transpire when corporations : What matters do transpire when corporations are considered the same as citizens by law?

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