Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9531252

Have any Question?


Related Questions in C/C++

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As