Em Andamento

Queues and Templates

For this assignment, you are to write an implementation of a Queue class. The Queue will be stored as a linked list, which will allow the Queue to easily grow and shrink as needed. To increase the usefulness of the Queue, it will be implemented as a template.

The methods to be implemented are described below. A driver program, ***[url removed, login to view]***, will be provided in order to test your class. The expected output from the driver program is also provided.

* * *

# struct QNode

The QNode structure is used as a building block to create the linked list version of the Queue. The reason that a structure is being used for QNode is because its data members are frequently accessed by the Queue class.

Because its definition is so closely tied to the Queue class described below, the definition and implementation for QNode should be placed in the header file ***Queue.h*** (i.e. the same one that will be used for the Queue class). Notice that both the definition and implementation are contained in the same file.

When this QNode is used, it should be able to hold any type of data, therefore it should be implemented as a template structure. This is done in the same way as template classes.

## Data Members

The structure must contain two data members:

1. a data element which can hold the data of interest

2. a pointer to a QNode of the appropriate type, which points to the next node in the linked list

## Constructor: **QNode( T = T(), QNode * = 0 )**

The constructor for the QNode structure should use the passed in arguments to initialize the two data members.

* * *

# class Queue

The definition and implementation for the Queue class should be placed in the header file ***Queue.h***. Notice that both the definition and implementation are contained in the same file.

When this Queue is used, it should be able to hold any type of data, therefore it should be implemented as a template class.

## Return Codes

There are two return codes associated with this class. Implement them as symbolic constants in the class header file. The names of the return codes are Q_OK and Q_FAIL and their values are 0 and -1 respectively.

## Deliverables

## Continued from above

Data Members

The class must contain three data members that are not available to the outside world.

1. a pointer to a QNode of the appropriate type, which points to the item at the front of the queue

2. a pointer to a QNode of the appropriate type, which points to the item at the rear of the queue

3. an integer that holds the number of nodes in the queue

## Constructors and Methods

The prototypes that follow are assuming that the class definition is preceded with:

template <class T>

### **Queue()**

This is the default constructor for the class. It should initialize the two pointers to NULL and set the number of nodes in the list to 0 to indicate that the queue is empty.

### **Queue( const Queue<T> & )**

This is the copy constructor for the class. It should create an instance of the Queue class that is a copy of the passed in Queue object. This can be easily implemented by calling the create() method described below.

### **~Queue()**

This is the destructor for this class. It should release each node in the Queue. This can be easily implemented by calling the destroy() method described below.

### **bool empty() const**

This function should return a boolean true value if the queue is empty, otherwise it should return false. There are a few different ways to implement this method, use the one that is obvious to you.

### **int size() const**

This function should return the number of nodes that are currently in the queue.

### **void clear()**

This function creates an empty queue. It should release all of the dynamic memory associated with the queue (i.e. call destroy()), set the front and rear pointers to indicate an empty queue, and reset the node counter to indicate an empty queue.

### **int push ( const T & )**

This is the routine that will be used to insert an item into the queue. The passed in argument is a reference to a constant item to be pushed onto the queue. If the queue is empty, then both the front and rear pointers will point at the new node. If the queue is not empty, then the node is inserted at the rear of the queue. In either case, increment the number of nodes in the queue and return Q_OK.

### **int pop()**

This is the routine that will be used to remove the front item from the queue. If the queue is empty, return Q_FAIL. If the queue is not empty, then remove the front item of the queue, update the front pointer and number of nodes, and return Q_OK.

### **int front (T &)**

This routine will be used determine the value of the item at the front of the queue. If the queue is empty, then return Q_FAIL. If the queue is not empty, pass back the data field of the item at the front of the queue (DO NOT remove it from the queue) and return Q_OK.

### **int rear (T &)**

This routine will be used determine the value of the item at the rear of the queue. If the queue is empty, then return Q_FAIL. If the queue is not empty, pass back the data field of the item at the rear of the queue (DO NOT remove it from the queue) and return Q_OK.

## Platform

Unix compiler using Tera Term Pro 2.3 software

The rest of the requirements and the whole assignment is at [[url removed, login to view]][1]. Then go to the WEB PAGES link. Then go to CSCI 241 COURSE INFORMATION. Then scroll down to COURSE INFORMATION and click on ASSIGNMENTS. Click Assignment 8. This is the assignment to be done. There is also a driver program and driver program output. This must be checked and have the right output in order for the assignment to be complete.

Habilidades: Programação C, Engenharia, Linux, MySQL, PHP, Arquitetura de software, Teste de Software, UNIX

Ver mais: world programming, web programming course, use of pointers in data structure, use of data structure in programming, type of queue in data structure, type of data structure in c, type of data structure, templates web pages, templates for web pages, symbolic programming, struct c programming, software for dynamic programming, software for building php codes, queue template, queues in data structure, queue program in data structure, queue in data structure, queue implementation in data structure, queue definition in data structure, queue data structure in c, queue data structure, pro web templates, programming pointers, programming definition, programming class definition

Acerca do Empregador:
( 2 comentários ) United States

ID do Projeto: #3008071

Premiar a:

teamvw

See private message.

$17 USD em 3 dias
(36 Avaliações)
3.8

13 freelancers estão ofertando em média $28 para este trabalho

mihaiscortaru

See private message.

$24.57 USD in 3 dias
(160 Comentários)
6.0
shahizanvw

See private message.

$8.5 USD in 3 dias
(46 Comentários)
4.6
exceptionalcoder

See private message.

$42.5 USD in 3 dias
(9 Comentários)
4.1
shashikhanvw

See private message.

$102 USD in 3 dias
(15 Comentários)
3.8
sonersen

See private message.

$22.1 USD in 3 dias
(11 Comentários)
2.8
ciphereye

See private message.

$11.05 USD in 3 dias
(16 Comentários)
2.7
claudiuvw

See private message.

$42.5 USD in 3 dias
(1 Comentário)
2.3
kartanvw

See private message.

$11.05 USD in 3 dias
(5 Comentários)
1.8
rosoftteam

See private message.

$11.05 USD in 3 dias
(3 Comentários)
1.4
thanasisk

See private message.

$42.5 USD in 3 dias
(5 Comentários)
0.9
gayathrinivas

See private message.

$12.75 USD in 3 dias
(1 Comentário)
0.0
roard

See private message.

$11.05 USD in 3 dias
(1 Comentário)
0.0