Creates and implements a class to represent the queue, C/C++ Programming

Assignment Help:

Purpose

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 |QNode| 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 QNode|

                      /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 |QNode|. 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 |QNode|s. 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 a |friend| 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.


Related Discussions:- Creates and implements a class to represent the queue

C program for select the char which u want , C Program for SELECT THE CHAR ...

C Program for SELECT THE CHAR WHICH U WANT #include stdio.h> #include conio.h> void main() {             void substr(char[], int *, int *);           int a,b

Constants, explain about symbolic constants with examples

explain about symbolic constants with examples

Define register simply with bit fields, Define register with bit fields? ...

Define register with bit fields? We could define register simply with bit fields: struct DISK_REGISTER { unsigned ready:1; unsigned error_occured:1; unsigned disk_spinni

When i develop a destructor, When I develop a destructor, do I require to e...

When I develop a destructor, do I require to explicitly call the destructors for my member objects?

C program for pattern star, 1 PETTERN1 (Pettern1.c)   main() { ...

1 PETTERN1 (Pettern1.c)   main() {           int i,j,k=1,a;           clrscr();           for(i=1;i           {                    if(i>=3)

Identifier and constant, What are  Id e n t i f ie rs a n d C o...

What are  Id e n t i f ie rs a n d C o n s t a n ts in C++? Id e n t i f ie r a n d C o n s t a n t : I d e n t i f ie r

Charity Ball Organizer, Charity Ball Organizer Many charities support good...

Charity Ball Organizer Many charities support good causes, but one of the difficulties each of them has is organizing their fundraising events. After nearly a semester of C progra

Assignment, (RationalNumber Class) A rational number is a number that can b...

(RationalNumber Class) A rational number is a number that can be represented as the quotient of two integers. For example, 1/3, 5/7, 7/2, and so forth are rational numbers (By 2/1

Explain function templates, Function Templates Function templates give ...

Function Templates Function templates give you with the capability to write a one function that is a skeleton, or template, for a family of similar functions. In function ov

Arrays within a class, A r r a y s w i t h i n a c l a s s:...

A r r a y s w i t h i n a c l a s s: I t i s j u s t d ecl a r i n g o r c on s t ru c ti n g a d e r i v e d t

Write Your Message!

Captcha
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