Write a program in java for the deque data structure

Assignment Help Computer Engineering
Reference no: EM132117520

This question is written in java. You are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. The problem needs to work like the example below.

A deque is a data structure consisting of a list of items, on which the following operations are possible:

push(x): Insert item x on the front end of the deque.

pop(): Remove the front item from the deque and return it.

inject(x): Insert item x on the rear end of the deque.

eject(): Remove the rear item from the deque and return it.

Write a program in Java for the deque data structure. All the above operations should take O(1) time per operation. Your program should create a menu-driven interface as shown in the example below.

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 1

Enter element to push: 5

Current Deque: 5

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 3

Enter element to inject: 79

Current Deque: 5 79

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 3

Enter element to inject: 23

Current Deque: 5 79 23

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 1

Enter element to push: 16

Current Deque: 16 5 79 23

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 1

Enter element to push: 59

Current Deque: 59 16 5 79 23

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 2

Current Deque: 16 5 79 23

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 4

Current Deque: 16 5 79

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 4

Current Deque: 16 5

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 2

Current Deque: 5

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 4

Current Deque:

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 2

Deque is empty, nothing to pop.

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 4

Deque is empty, nothing to eject.

Enter operation for deque (1: Push, 2: Pop, 3: Inject, 4: Eject, 5: Quit): 5

Bye!

Reference no: EM132117520

Questions Cloud

Advise gregs child ex-wife and mother : MLM727 – Superannuation Law and Policy - Advise Greg's child, ex-wife and mother - wishes to contribute to her own superannuation fund
What is your vision of nursing for the future : Summary that includes answers to the following questions: What are the challenges that you will face as a nurse?
Business workflow system-software product : What would be the strength and weaknesses of SAP Business Workflow system/software product?
Do you believe in health care for everyone : Professor requirement: Moving forward on all future discussion boards, please use APA format and references. Utilize more than one reference to answer.
Write a program in java for the deque data structure : Write a program in Java for the deque data structure. All the above operations should take O(1) time per operation.
Replacing some functions of email in business : How is instant messaging/texting replacing some functions of email in business? What are the advantages and disadvantages of business use of text messaging?
Prepare a shortened version of your final paper : The primary goal of this weekly assignment is to enable you to understand the revision process and revise your paper with the help of a writing specialist.
Write a program called circle that displays a circle : Write a program called Circle that displays a circle in the upper right quadrant of the Cartesian plane.
The camera system and a cop walking around : A company in the Netherlands that makes navigation devices collects location data from the devices to provide real-time services to its customers.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Which strings is not generated by the grammar

What is the decimal value of the sum of the binary number 11001 and hexadecimal number 84 - Which of these are not desired characteristics of a hash function in used to construct a hash table?

  Calculate the average waiting time for each algorithm

FCFS, nonpreemptive SJF, nonpreemptive priority and calculate the average waiting time for each algorithm.

  Write argumentative research paper on robots argumentative

Write an argumentative research paper on robots Argumentative: A research paper in which you provide a clear stance, also called a thesis statement.

  List and describe the stages of an lca

List and describe the stages of an LCA. List and describe the key elements of an LCA. List and describe the impact metric (factors) of an LCA.

  Compute the total resistance in a circuit

A program is needed to calculate the total resistance in a circuit. The resistors can either be in series or in parallel but not both. The number of resistors in the circuit can range from 2 to 10. How do I get started?

  What capabilities does oracle have as a support tool

What capabilities does Oracle have as a support tool? What is computer forensics? Name some commonly used computer forensics tools.

  Prove that best parallel algorithm written for n-processor

Prove that the best parallel algorithm written for an n-processor ERE\N PRAM model can be no more than O[log n} times slower than any algorithm for CRCW model.

  Discuss important to harden a computer system or network

Explain why it is important to harden a computer system or network, citing information from your article to support your response

  How star configuration with a single router in the middle

A seven-story office building has 15 adjacent offices per floor. Each office contains the wall socket for a terminal in the front wall, so the sockets form a rectangular grid in the vertical plane, with a separation of 4 meters between sockets, bo..

  Overview of the cryptography domain

Overview of the Cryptography Domain, Describe the operation of a one-time pad (OTP) and give an example of a device that uses an OTP from research

  Create a global function called updatebucket

Create a global function called "updatebucket(TetrisShape localTetrisShape)" to populate the bucket with values of the "shapeArray". Here, you will use two nested for loops to go over the shapeArray of 4x4.

  Discuss common input -output technologies.

Discuss common input / output technologies.Use technology and information resources to research issues in enterprise architecture.

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