Write a program in java for the deque data structure

Assignment Help JAVA Programming
Reference no: EM132117476

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: EM132117476

Questions Cloud

Searcher for consensus but a molder of consensus : Martin Luther King Jr. once proclaimed, "A genuine leader is not a searcher for consensus but a molder of consensus.
Describe object-oriented unit testing : Write Purpose of SOP and Detailed description of Moodle Assignment procedure for our college- based on best practice/standards.
How might earlier collaboration have been beneficial : Explain the conflict resolution skills displayed by the leader in the scenario. On a scale of 1-10, how would you rate those of the leader.
Discuss qualitative techniques in research : Discuss qualitative techniques in research. Development of the topic in general of the qualitative techniques.
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.
Maslow hierarchy various stages or levels of needs : In reference to Maslow's Hierarchy various stages or levels of needs. Explain how an employee's stage in the Hierarchy might affect the type of benefits he/she
List from challenges of implementing an erp system : How could core ERP components help improve business operations at a University? List from challenges of implementing an ERP system at a University.
Do you feel that affirmative action : Do you feel that affirmative action is a good way to remedy past discrimination? Why or Why not?
List the binary address and the tag : For each reference, list the binary address, the tag, the index, and if the reference is a hit or a miss, assuming the cache is initially empty.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program that finds the temperature

Write a JAVA program that finds the temperature that is the same in both Celsius and Fahrenheit

  Describe principles of data abstraction and inheritance

Study the principles of data abstraction, inheritance and dynamic binding. Use Library to get started on finding resources.You must take the terms and describe it.

  Create a graphical user interface that has two buttons

Create a Graphical User Interface that has two buttons and a textArea. Create a String array to store the following messages (Enter your name where it says YourName).

  Define an adt for character strings.

Define an ADT for character strings. Your ADT should consist of typical functions that can be performed on strings, with each function defined in terms of its input and output. Then define two different physical representations for strings.

  1 gqueuea queue is an ordered collection of items in which

1 gqueuea queue is an ordered collection of items in which the removal of items is restricted to the fifo rst in rst

  Write a program in java for bank system

Write a program in java for Bank System - create an instance for the customer using their name and an account number of your choice.

  Compute a java programming writing a number converter

Compute a Java Programming - Writing a number converter. Surgeons have a very tough schedule throughout the day to deal with patients, perform surgeries, visit wards, and attend meetings among others.

  Algorithm analysis with advanced data structures

Algorithm Analysis with Advanced Data Structures, Your good friend, a Rock Star, asked you to create a Time Manager app for him, The Rock Star performs gigs at certain dates, all around the country - at most one gig per day

  Program to computes the average of all three scores

Write a program the does the Reads scores of three different classes - Prints input scores, average and the letter grade

  Write a calculator application that accepts two numbers

Write a calculator application that accepts two numbers - Write an employee management application - The minimum and maximum ages are 20 and 58, respectively

  The frantic pipe layer game1 the completed gamehere is what

the frantic pipe layer game.1 the completed gamehere is what the user interface should look like when completedyou must

  Create a program that develops an amortization schedule

Create a program that develops an amortization schedule. Your program should be written as a Java applet.

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