This assignment is an exercise

Assignment Help Basic Computer Science
Reference no: EM13166238

This assignment is an exercise in implementing the queue ADT using a singly-linked list. This assignment also introduces the concept of templates.

Assignment

This program creates and implements a class to represent the Queue ADT using a singly-linked list.

A driver program is provided for this assignment to test your implementation. You don't have to write the tests.

Program

You will need to write one template structure and one template class for this assignment, called Node and Queue. You will need to implement several methods and functions associated with these data types.

Since these are both C++ templates and are closely related to each other, all of your code should be placed in a single header (.h) file. This includes the implementations of all methods and any other associated functions.

struct Node

Data members

This template structure should have two data members: a member of the template parameter type to store an item to be inserted into the queue, and a pointer to a Node. The pointer next will point to the next node in the linked list (or be NULL if this is the last node in the list).

Since the Queue class will need access to these data members, make them public (the default for a struct).

Methods

  • Constructor

    The structure should have one constructor that takes an argument of the template parameter type. Make this argument a reference to const data. The constructor should copy the argument into the queue node and set the node's pointer to NULL.

class Queue

Data members

This class should have two data members, both pointers to Nodes. The pointer qFront will point to the front node in the queue (or be NULL if the queue is empty); the pointer qRear will point to the rear node in the queue (or be NULL if the queue is empty).

Methods and associated functions

  • Constructor

    The class should have a default constructor that takes no arguments. The constructor should set both pointer data members to NULL.

  • Destructor

    The class should have a destructor. The destructor can simply call the clear() method described below.

  • Copy constructor

    The class should also have a proper copy constructor. If you choose to make a copy of the linked list by using the push method, make sure you set both the front and rear pointers for the new queue to NULL before you attempt to insert any nodes into it.

  • operator=

    The assignment operator should be properly overloaded.

  • operator<<

    The output operator should be overloaded so that an entire Queue can be sent to the standard output. As usual, this function will need to be a friend rather than a method. Declaring a template function to be afriend of a template class requires some special syntax - see the Implementation Hints below.

  • clear()

    This method takes no arguments and returns nothing. It should properly set the queue back to the empty state. That means deleting all of the nodes in the queue and setting the front and rear pointers back to NULL.

  • size()

    This method takes no arguments and returns an integer. It should return the current size of the queue; i.e., the number of data items currently stored in the queue. Since this is not stored as a data member of the queue class, you will have to traverse the linked list and count the nodes.

  • empty()

    Returns true if there are no data items currently stored in the queue; otherwise returns false.

  • front()

    This method takes no arguments and returns the template parameter type. If the queue is empty, this method should throw an out_of_range exception. Otherwise, it should return the data stored in the front node of the queue.

  • back()

    This method takes no arguments and returns the template parameter type. If the queue is empty, this method should throw an out_of_range exception. Otherwise, it should return the data stored in the rear node of the queue.

  • push()

    This method takes a reference to a constant item of the template parameter type as its argument (the item to insert into the queue). It returns nothing. The method should insert the item at the rear of the queue.

  • pop()

    This method takes no arguments and returns nothing. If the queue is empty, this method should throw an out_of_range exception. Otherwise, it should remove the item at the front of the queue.

If you like, you may write private methods for the Queue class in addition to the methods described above. For example, you may want to write a copyList() method that can be called by both the copy constructor and overloaded assignment operator.

Reference no: EM13166238

Questions Cloud

Calculate the amount of heat liberated : Calculate the amount of heat liberated (in kJ) from 417 g of mercury when it cools from 64.0°C to 12.0°C.
Calculate the vapor pressure of diethyl : Diethyl ether is a volatile organic compound. The vapor pressure of diethyl ether is 401 mm Hg at 18°C and the Hvap = 26.0 kJ/mol. Calculate the vapor pressure of diethyl ether at 40°C.
Depict an ionization reaction for benzoic acid : using all atoms and bond structure, show an ionization reaction for benzoic acid
Writing a program to have it generate random words : How would I go about writing a program to have it generate random words with a letter missing for a child to guess? Maybe it would have three letters, then four, next five, and so on until maybe 10 letters. Please keep in mind that I'd like it to wor..
This assignment is an exercise : If you like, you may write private methods for the Queue class in addition to the methods described above. For example, you may want to write a copyList() method that can be called by both the copy constructor and overloaded assignment operator.
Non-trads face in acquiring a higher education : What conflicts do non-trads face in acquiring a higher education that traditional students do not?
State titration between a solution of ammonium : you perform a titration between a solution of ammonium (Kb = 1.8*10^-5) and HCL. you have a 200 ml of 50.0mM ammonium solution titrated against
That takes the time as six integer arguments : Write a C function seconds_since_jan1() that takes the time as six integer arguments (year, month, day, hour, minute, and second) and returns the number of seconds since the beginning of the year.
Eventual path to peaceful coexistence could be paved : Naming one or two factors you feel contributed to this state of affairs? In what ways did the foreign policy of the US or USSR soften so that the eventual path to peaceful coexistence could be paved?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Compute number of total bits needed to implement cache

Suppose a computer's address size is K bits (using byte addressing), the cache size is k bits (using byte addressing), the cache size is S bytes. Compute the number of total bits needed to implement the cache.

  Gradesaverage, which prompts user

Write a program called GradesAverage, which prompts user for the number of students, reads it from the keyboard, and saves it in an int variable called numStudents. It then prompts user for the grades of each of the students and saves them in an i..

  Convert decimal number in sixteen bit binary

Convert decimal number +25 and +3 in 16-bit binary. Illustrate your work. Add binary numbers in above question using rules for binary addition.

  Designing a 24 cpu multiprocessor chip

designing a 24 CPU multiprocessor chip to compete with Intel PHI at a lower price point. Each core will run at 2 GHz and have a 32Kb L1 cache, 50ps access (per word), 8 word blocks, 4-way associative, write-through, 1% miss ratio There is a 6Mb L2 ca..

  Describing targeted audience go for particular site

Recognize a particular website that you frequently go to and explain targeted audience that goes to that particular site. Do not say "everyone" since all sites always have general target audience.

  Creating a payoff table for decision

Amy decided to select the best option which will minimize her total 36-month cost. Difficult is that Amy is not sure how many miles she will drive over next three years. Create payoff table for Amy's decision.

  Reason for problem encounter in deleting path variables

Discuss some of the problems he may soon encounter and explain the reasons for these problems. How could he easily return path to its original value?

  Tools or tactics for risks for computing infrastructure

As part of project to assess security risks for computing infrastructure, you have found that other managers often have different idea. List any tools or tactics that could be used.

  Will action alter or destroy any historical and scientific

Will action alter or destroy any historical, scientific, or archaeological site? New engineering building project doesn't have any reported historical, scientific.

  Variety of tools that use to prepare project

In this course, you looked at a variety of tools that you would use to prepare a project. Some areas you looked at included, but were not limited to?

  Explaining binary normalization shift-and-subtract

Convert input arguments to binary. Binary normalization shift-and-subtract.

  Explain performance which is boost by new version of chip

Let the following hypothetical news release: "Company will unveil industry's first 5 GHz version of chip, which presents 25% performance boost over company's former speed champ. Explain the definition (or definitions) of performance.

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