1 gqueuea queue is an ordered collection of items in which

Assignment Help JAVA Programming
Reference no: EM13347239

1: GQueue

A queue is an ordered collection of items in which the removal of items is restricted to the FIFO ( rst in rst out) principle. That is, the rst item added to the queue will be the rst
one removed, the second added will be the second removed, etc.

When you are standing in line waiting for a bank teller, you are in a queue of people. The rst in the line is the rst to be served. The next in line is the second to be served (or removed from the queue). Using this understanding of a queue, we will say that items added to a queue are added to the back of the queue (i.e., you go to the back of the line when you add yourself to the line). The word for adding an element to a queue is enqueue. When we remove an item for a queue, we remove it from the front of the queue (i.e., if you are next to be served in the line, you are at the front of the line). The word for removing an item from
a queue is dequeue.

Recall that we used top for the place where we add and remove elements from a Stack. While this word has a natural meaning to us, it should reveal how the Stack ADT is imple-
mented in code. Similarly, we use back and front for the two \ends" of a queue, but these words do not necessarily relate to the actual data structures used to implement a Queue
ADT.

In this assignment, you will write code for a generic Queue ADT, which we will call GQueue. Here is the ADT for a Queue:

Queue
data                                                               operations
an ordered collection of items                      - add an item to the collection
(need not be unique)                                   - remove an item from the collection using FIFO principle
                                                                    - ask if the collection is empty or not
                                                                    - ask what the next item removed would be
                                                                    - ask how many items are in the collection

Your Java class must use generics for the data type of the elements in the queue. Your class must implement the Comparable interface.
Your generic Queue implementation should have the following public methods and constructors (with appropriate return and input argument types):

public boolean enqueue(...)
// purpose: add an item to the back of the queue if possible
--> // preconditions: item added must be same type as specified when this was created
// postconditions: if size of the queue is < capacity of the queue
//                          adds the item to the queue,
//                          the size of the queue is incremented by 1,
//                          returns true
//                          otherwise (the size of the queue = capacity of the queue)
//                          return false and do nothing
dequeue()
// purpose: retrieve the item from the front of the queue
// preconditions: the queue must be non-empty
// postconditions: returns the item at the front of the queue
//                          that item is removed from the queue
//                          the size of the queue is decremented by 1
isEmpty()
// purpose: asks if the queue is empty or not
// postconditions: returns true if the queue is empty
//                          returns false if there is 1 or more items in the queue
size()
// purpose: returns the size of the queue
// postconditions: returns the number of items in the queue
peek()
// purpose: ask what item is at the front of the queue
// preconditions: the queue must be non-empty
// postconditions: returns the item at the front of the queue
//                          (does not remove the item)
//                          (does not decrement size)
-> isFull()
// purpose: ask if there is room to add an item to the queue
// postconditions: returns true if the queue is full (it has reached its capacity)
//                          returns false if there is room to add at least one more item
GQueue(int n)
// purpose: create an empty queue with capacity n
// preconditions: none
// postconditions: creates an empty queue with capacity n
//                          (the queue can store up to n items at any given time)

Reference no: EM13347239

Previous Q& A

  Question 1the current selling price is 90 per unit and

question 1the current selling price is 90 per unit and variable expenses are 60 per unit. fixed expenses are 810000 per

  Question onea the probability that a bomber sets a target

question one.a the probability that a bomber sets a target on a bombing mission is 0.70 three bombers are sent to bomb

  Toms pizza sells for 500 ea and serves an average of 425

toms pizza sells for 5.00 ea and serves an average of 425 customers per week. during a recent sale tom lowered the

  1 explain the differences between our specifications of the

1. explain the differences between our specifications of the sorted list adt and the binary search tree adt.2. define a

  Write a paper describing the influence the experiences have

write a paper describing the influence the experiences have made on the persons development. bulldiscuss the social

  1a substantial percentage of the companies noted on the

1a substantial percentage of the companies noted on the nyse and nasdaq dont pay dividends but investors are

  1 rock-paper-scissors simplejavaproblems 1-3 are based on

1 rock-paper-scissors simple.javaproblems 1-3 are based on the rock-paper-scissors game. if you are unfamiliar with

  At-f 7357r 83 df 4df 3203df 98 p gt 05

assignment-f 7.357r .83 df 4df 3203df 98 p gt .05 p lt .05 p lt .01question 1. what statistical

  Part-1you are required to research a suitable organisation

part-1you are required to research a suitable organisation of your choice and in a formal report undertake the

  Explaining the statement consider the role of the hr

explaining the statement consider the role of the hr department facilitator or organiser? should include reference

Reviews

Write a Review

 

Similar Q& A

  Write java program to utilizes gui with five text fields

Write down the program called MaxMinAvgGUI.java which utilizes GUI with five(5)text fields which asks user to enter 5(five) decimal numbers. 1(one)number in each text field.

  Information systems to strengthen customer

Which of the following illustrates the use of information systems to strengthen customer and supplier intimacy? BPM is considered concluded when the new processes are both implemented and accepted.

  Program produces 1000 integer ranging

Then your program produces 1000 integer ranging from 1to 10000 in the array and then sort them in ascending order and then print the result into data.txt file. (You may list integers separated by space or new line)

  To translate infix mathematical expression

Write a program in java to translate infix mathematical expression into postfix expression and a program to evaluate the postfix expression

  Populate a one-dimensional array

Populate a one-dimensional array with the following grades in this order: 93, 61, 72, 45, 84, 51, 70, 83, 96, and 66. Use a loop to call a method from main() that adds

  Write a java program to implement the finite field

Write a program called "GF2.java" to implement the finite field GF(p n ) where p is a prime number and n is a positive integer.  You also need to write four methods to realize "+", "-", "´", and "/".

  Demonstrates conditions under which the compareto() method

Write an application that demonstrates conditions under which the compareTo() method retrun a positive number, a negative number, and a zero when used to compare two Strings, Save the file as CompareStringValues.java. Lab Assignment

  Write java program to print strings given at command line

Write a program Average.java which just prints strings that it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Java application to declare and create a vector

Write a java application that perform the following task: declare and create a vector with initial size of 10, increment of 2

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  Overriding the equals method

Use the equals method, which Player inherits from the Object class, to determine whether two players are the same. Are the results what you expect?

  How many numbers do you want to enter

Write a program that asks the user "How many numbers do you want to enter?" With that value, create an array that is big enough to hold that amount of numbers (integers).

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